Skip to content

Commit 0b7129a

Browse files
authored
[InstCombine] Fix FMF propagation in foldFCmpFSubIntoFCmp (#161539)
Proof: https://alive2.llvm.org/ce/z/orSP-S Closes #161525.
1 parent c470982 commit 0b7129a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8527,6 +8527,9 @@ static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
85278527
DenormalMode::getIEEE()) {
85288528
CI.replaceOperand(I, 0, X);
85298529
CI.replaceOperand(I, 1, Y);
8530+
I.setHasNoInfs(LHSI->hasNoInfs());
8531+
if (LHSI->hasNoNaNs())
8532+
I.setHasNoNaNs(true);
85308533
return &I;
85318534
}
85328535
break;

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,46 @@ define i1 @fcmp_ule_fsub_const(float %x, float %y) {
18121812
ret i1 %cmp
18131813
}
18141814

1815+
define i1 @fcmp_ninf_ule_fsub_const(float %x, float %y) {
1816+
; CHECK-LABEL: @fcmp_ninf_ule_fsub_const(
1817+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[X:%.*]], [[Y:%.*]]
1818+
; CHECK-NEXT: ret i1 [[CMP]]
1819+
;
1820+
%fs = fsub float %x, %y
1821+
%cmp = fcmp ninf ule float %fs, 0.000000e+00
1822+
ret i1 %cmp
1823+
}
1824+
1825+
define i1 @fcmp_nnan_ule_fsub_const(float %x, float %y) {
1826+
; CHECK-LABEL: @fcmp_nnan_ule_fsub_const(
1827+
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ule float [[X:%.*]], [[Y:%.*]]
1828+
; CHECK-NEXT: ret i1 [[CMP]]
1829+
;
1830+
%fs = fsub float %x, %y
1831+
%cmp = fcmp nnan ule float %fs, 0.000000e+00
1832+
ret i1 %cmp
1833+
}
1834+
1835+
define i1 @fcmp_ule_fsub_ninf_const(float %x, float %y) {
1836+
; CHECK-LABEL: @fcmp_ule_fsub_ninf_const(
1837+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ule float [[X:%.*]], [[Y:%.*]]
1838+
; CHECK-NEXT: ret i1 [[CMP]]
1839+
;
1840+
%fs = fsub ninf float %x, %y
1841+
%cmp = fcmp ule float %fs, 0.000000e+00
1842+
ret i1 %cmp
1843+
}
1844+
1845+
define i1 @fcmp_ule_fsub_nnan_const(float %x, float %y) {
1846+
; CHECK-LABEL: @fcmp_ule_fsub_nnan_const(
1847+
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ule float [[X:%.*]], [[Y:%.*]]
1848+
; CHECK-NEXT: ret i1 [[CMP]]
1849+
;
1850+
%fs = fsub nnan float %x, %y
1851+
%cmp = fcmp ule float %fs, 0.000000e+00
1852+
ret i1 %cmp
1853+
}
1854+
18151855
define i1 @fcmp_ugt_fsub_const(float %x, float %y) {
18161856
; CHECK-LABEL: @fcmp_ugt_fsub_const(
18171857
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]

0 commit comments

Comments
 (0)