Skip to content

Commit 44f109f

Browse files
committed
[InstCombine] Only preserve the flags from rhs when the and is not logical
1 parent f3b8f0d commit 44f109f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,10 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS,
14441444
}
14451445
if (IsLessThanOrLessEqual(IsAnd ? PredL : PredR)) {
14461446
BuilderTy::FastMathFlagGuard Guard(Builder);
1447-
Builder.setFastMathFlags(LHS->getFastMathFlags() |
1448-
RHS->getFastMathFlags());
1447+
FastMathFlags NewFlag = LHS->getFastMathFlags();
1448+
if (!IsLogicalSelect)
1449+
NewFlag |= RHS->getFastMathFlags();
1450+
Builder.setFastMathFlags(NewFlag);
14491451

14501452
Value *FAbs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, LHS0);
14511453
return Builder.CreateFCmp(PredL, FAbs,

llvm/test/Transforms/InstCombine/fcmp-range-check-idiom.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ define i1 @test_and_olt_fmf_propagation_union(float %x) {
363363
define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(float %x) {
364364
; CHECK-LABEL: define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(
365365
; CHECK-SAME: float [[X:%.*]]) {
366-
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[X]])
367-
; CHECK-NEXT: [[COND:%.*]] = fcmp ninf olt float [[TMP1]], 0x3C00000000000000
366+
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float [[X]])
367+
; CHECK-NEXT: [[COND:%.*]] = fcmp olt float [[TMP1]], 0x3C00000000000000
368368
; CHECK-NEXT: ret i1 [[COND]]
369369
;
370370
%cmp1 = fcmp ninf olt float %x, 0x3C00000000000000

0 commit comments

Comments
 (0)