Skip to content

[InstCombine] Preserve the flag from RHS only if the and is bitwise #113164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,10 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS,
}
if (IsLessThanOrLessEqual(IsAnd ? PredL : PredR)) {
BuilderTy::FastMathFlagGuard Guard(Builder);
Builder.setFastMathFlags(LHS->getFastMathFlags() |
RHS->getFastMathFlags());
FastMathFlags NewFlag = LHS->getFastMathFlags();
if (!IsLogicalSelect)
NewFlag |= RHS->getFastMathFlags();
Builder.setFastMathFlags(NewFlag);

Value *FAbs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, LHS0);
return Builder.CreateFCmp(PredL, FAbs,
Expand Down
39 changes: 39 additions & 0 deletions llvm/test/Transforms/InstCombine/fcmp-range-check-idiom.ll
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,42 @@ define i1 @test_and_olt_fmf_propagation_union(float %x) {
%cond = and i1 %cmp1, %cmp2
ret i1 %cond
}

define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(float %x) {
; CHECK-LABEL: define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(
; CHECK-SAME: float [[X:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float [[X]])
; CHECK-NEXT: [[COND:%.*]] = fcmp olt float [[TMP1]], 0x3C00000000000000
; CHECK-NEXT: ret i1 [[COND]]
;
%cmp1 = fcmp ninf olt float %x, 0x3C00000000000000
%cmp2 = fcmp ogt float %x, 0xBC00000000000000
%cond = select i1 %cmp2, i1 %cmp1, i1 false
ret i1 %cond
}

define i1 @test_and_olt_fmf_propagation_union_logical_lhs_poison(float %x) {
; CHECK-LABEL: define i1 @test_and_olt_fmf_propagation_union_logical_lhs_poison(
; CHECK-SAME: float [[X:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[X]])
; CHECK-NEXT: [[COND:%.*]] = fcmp ninf olt float [[TMP1]], 0x3C00000000000000
; CHECK-NEXT: ret i1 [[COND]]
;
%cmp1 = fcmp olt float %x, 0x3C00000000000000
%cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000
%cond = select i1 %cmp2, i1 %cmp1, i1 false
ret i1 %cond
}

define i1 @test_and_olt_fmf_propagation_union_logical_both_poison(float %x) {
; CHECK-LABEL: define i1 @test_and_olt_fmf_propagation_union_logical_both_poison(
; CHECK-SAME: float [[X:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[X]])
; CHECK-NEXT: [[COND:%.*]] = fcmp ninf olt float [[TMP1]], 0x3C00000000000000
; CHECK-NEXT: ret i1 [[COND]]
;
%cmp1 = fcmp ninf olt float %x, 0x3C00000000000000
%cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000
%cond = select i1 %cmp2, i1 %cmp1, i1 false
ret i1 %cond
}
Loading