Skip to content

Commit 7cb989a

Browse files
committed
[InstCombine] Do not fold logical is_finite test
1 parent 7e531fd commit 7cb989a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,9 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS,
14801480
}
14811481
}
14821482

1483-
if (IsAnd && stripSignOnlyFPOps(LHS0) == stripSignOnlyFPOps(RHS0)) {
1483+
// This transform is not valid for a logical select.
1484+
if (!IsLogicalSelect && IsAnd &&
1485+
stripSignOnlyFPOps(LHS0) == stripSignOnlyFPOps(RHS0)) {
14841486
// and (fcmp ord x, 0), (fcmp u* x, inf) -> fcmp o* x, inf
14851487
// and (fcmp ord x, 0), (fcmp u* fabs(x), inf) -> fcmp o* x, inf
14861488
if (Value *Left = matchIsFiniteTest(Builder, LHS, RHS))

llvm/test/Transforms/InstCombine/and-fcmp.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4993,7 +4993,9 @@ define i1 @clang_builtin_isnormal_inf_check_copysign(half %x, half %y) {
49934993
define i1 @clang_builtin_isnormal_inf_check_copysign_logical_select(half %x, half %y) {
49944994
; CHECK-LABEL: @clang_builtin_isnormal_inf_check_copysign_logical_select(
49954995
; CHECK-NEXT: [[COPYSIGN_X:%.*]] = call half @llvm.copysign.f16(half [[X:%.*]], half [[Y:%.*]])
4996-
; CHECK-NEXT: [[AND:%.*]] = fcmp oeq half [[COPYSIGN_X]], 0xH7C00
4996+
; CHECK-NEXT: [[ORD:%.*]] = fcmp ord half [[X]], 0xH0000
4997+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq half [[COPYSIGN_X]], 0xH7C00
4998+
; CHECK-NEXT: [[AND:%.*]] = select i1 [[ORD]], i1 [[CMP]], i1 false
49974999
; CHECK-NEXT: ret i1 [[AND]]
49985000
;
49995001
%copysign.x = call half @llvm.copysign.f16(half %x, half %y)
@@ -5005,7 +5007,7 @@ define i1 @clang_builtin_isnormal_inf_check_copysign_logical_select(half %x, hal
50055007

50065008
define i1 @clang_builtin_isnormal_inf_check_fabs_nnan_logical_select(half %x) {
50075009
; CHECK-LABEL: @clang_builtin_isnormal_inf_check_fabs_nnan_logical_select(
5008-
; CHECK-NEXT: [[COPYSIGN_X:%.*]] = call nnan half @llvm.fabs.f16(half [[X:%.*]])
5010+
; CHECK-NEXT: [[COPYSIGN_X:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]])
50095011
; CHECK-NEXT: [[AND:%.*]] = fcmp oeq half [[COPYSIGN_X]], 0xH7C00
50105012
; CHECK-NEXT: ret i1 [[AND]]
50115013
;

0 commit comments

Comments
 (0)