Skip to content

Commit d65b59f

Browse files
committed
adds negative tests
1 parent 70a1d95 commit d65b59f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8088,11 +8088,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
80888088
case FCmpInst::FCMP_OLE:
80898089
// Skip optimization: fsub x, y unless guaranteed !isinf(x) ||
80908090
// !isinf(y).
8091-
if (!LHSI->hasNoNaNs() && !LHSI->hasNoInfs() &&
8091+
if (!LHSI->hasOneUse() || (!LHSI->hasNoNaNs() && !LHSI->hasNoInfs() &&
80928092
!isKnownNeverInfinity(LHSI->getOperand(1), /*Depth=*/0,
80938093
getSimplifyQuery().getWithInstruction(&I)) &&
80948094
!isKnownNeverInfinity(LHSI->getOperand(0), /*Depth=*/0,
8095-
getSimplifyQuery().getWithInstruction(&I)))
8095+
getSimplifyQuery().getWithInstruction(&I))))
80968096
break;
80978097

80988098
[[fallthrough]];

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,16 +1721,31 @@ define <2 x i1> @fcmp_une_sel_x_negx_with_any_fpzero_nnan_vec(<2 x i1> %cond, <2
17211721

17221722
; negative test - extra use
17231723

1724-
define i1 @fcmp_ueq_fsub_const_extra_use(float %x, float %y) {
1725-
; CHECK-LABEL: @fcmp_ueq_fsub_const_extra_use(
1726-
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1724+
define i1 @fcmp_ueq_fsub_nnan_const_extra_use(float %x, float %y) {
1725+
; CHECK-LABEL: @fcmp_ueq_fsub_nnan_const_extra_use(
1726+
; CHECK-NEXT: [[FS:%.*]] = fsub nnan float [[X:%.*]], [[Y:%.*]]
17271727
; CHECK-NEXT: call void @use(float [[FS]])
1728-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[FS]], 0.000000e+00
1728+
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ueq float [[FS]], 0.000000e+00
17291729
; CHECK-NEXT: ret i1 [[CMP]]
17301730
;
1731-
%fs = fsub float %x, %y
1731+
%fs = fsub nnan float %x, %y
17321732
call void @use(float %fs)
1733-
%cmp = fcmp ueq float %fs, 0.000000e+00
1733+
%cmp = fcmp nnan ueq float %fs, 0.000000e+00
1734+
ret i1 %cmp
1735+
}
1736+
1737+
; negative test - extra use
1738+
1739+
define i1 @fcmp_oeq_fsub_ninf_const_extra_use(float %x, float %y) {
1740+
; CHECK-LABEL: @fcmp_oeq_fsub_ninf_const_extra_use(
1741+
; CHECK-NEXT: [[FS:%.*]] = fsub ninf float [[X:%.*]], [[Y:%.*]]
1742+
; CHECK-NEXT: call void @use(float [[FS]])
1743+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf oeq float [[FS]], 0.000000e+00
1744+
; CHECK-NEXT: ret i1 [[CMP]]
1745+
;
1746+
%fs = fsub ninf float %x, %y
1747+
call void @use(float %fs)
1748+
%cmp = fcmp ninf oeq float %fs, 0.000000e+00
17341749
ret i1 %cmp
17351750
}
17361751

0 commit comments

Comments
 (0)