Skip to content

Commit f0cdf4b

Browse files
committed
[InstCombine] Check FPMathOperator for Ctx before FMF check
We need to check FPMathOperator for Ctx instruction before checking fast math flag on this Ctx. Ctx is not always an FPMathOperator, so explicitly check for it. Fixes #71548.
1 parent 551c280 commit f0cdf4b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6606,7 +6606,8 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
66066606
// float, if the ninf flag is set.
66076607
const APFloat *C;
66086608
if (match(Op1, m_APFloat(C)) &&
6609-
(C->isInfinity() || (Q.CxtI->hasNoInfs() && C->isLargest()))) {
6609+
(C->isInfinity() || (isa<FPMathOperator>(Q.CxtI) &&
6610+
Q.CxtI->hasNoInfs() && C->isLargest()))) {
66106611
// minnum(X, -inf) -> -inf
66116612
// maxnum(X, +inf) -> +inf
66126613
// minimum(X, -inf) -> -inf if nnan

llvm/test/Transforms/InstCombine/minimum.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,29 @@ define double @negated_op_extra_use(double %x) {
471471
%r = call double @llvm.minimum.f64(double %negx, double %x)
472472
ret double %r
473473
}
474+
475+
; Testcase from PR 71548.
476+
define void @pr71548() {
477+
; CHECK-LABEL: @pr71548(
478+
; CHECK-NEXT: [[C0:%.*]] = load atomic double, ptr addrspace(1) null unordered, align 8
479+
; CHECK-NEXT: [[C1:%.*]] = load atomic i32, ptr addrspace(1) null unordered, align 4
480+
; CHECK-NEXT: [[C2:%.*]] = sitofp i32 [[C1]] to double
481+
; CHECK-NEXT: [[CRES_I:%.*]] = call noundef double @llvm.minimum.f64(double [[C0]], double [[C2]])
482+
; CHECK-NEXT: [[C3:%.*]] = fcmp ult double [[CRES_I]], 0.000000e+00
483+
; CHECK-NEXT: [[C_NOT16:%.*]] = icmp eq i32 [[C1]], 0
484+
; CHECK-NEXT: [[COR_COND45:%.*]] = or i1 [[C3]], [[C_NOT16]]
485+
; CHECK-NEXT: call void @llvm.assume(i1 [[COR_COND45]])
486+
; CHECK-NEXT: ret void
487+
;
488+
%c0 = load atomic double, ptr addrspace(1) null unordered, align 8
489+
%c1 = load atomic i32, ptr addrspace(1) null unordered, align 4
490+
%c2 = sitofp i32 %c1 to double
491+
%cres.i = call noundef double @llvm.minimum.f64(double %c0, double %c2)
492+
%c3 = fcmp ult double %cres.i, 0.000000e+00
493+
%c.not16 = icmp eq i32 %c1, 0
494+
%cor.cond45 = or i1 %c3, %c.not16
495+
call void @llvm.assume(i1 %cor.cond45)
496+
ret void
497+
}
498+
499+
declare void @llvm.assume(i1)

0 commit comments

Comments
 (0)