Skip to content

Commit 879940d

Browse files
committed
[InstCombine] Fold fcmp ogt (x - y), 0 into fcmp ogt x, y #85245
1 parent 864a886 commit 879940d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7972,6 +7972,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
79727972
Constant *RHSC;
79737973
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
79747974
switch (LHSI->getOpcode()) {
7975+
case Instruction::FSub:
7976+
if (Pred == FCmpInst::FCMP_OGT && match(RHSC, m_PosZeroFP()) &&
7977+
match(LHSI, m_OneUse(m_FSub(m_Value(X), m_Value(Y)))))
7978+
return new FCmpInst(Pred, X, Y);
7979+
break;
79757980
case Instruction::PHI:
79767981
if (Instruction *NV = foldOpIntoPhi(I, cast<PHINode>(LHSI)))
79777982
return NV;

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,3 +1284,26 @@ define <1 x i1> @bitcast_1vec_eq0(i32 %x) {
12841284
%cmp = fcmp oeq <1 x float> %f, zeroinitializer
12851285
ret <1 x i1> %cmp
12861286
}
1287+
1288+
define i1 @fcmp_fsub_const(float %x, float %y) {
1289+
; CHECK-LABEL: @fcmp_fsub_const(
1290+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[X:%.*]], [[Y:%.*]]
1291+
; CHECK-NEXT: ret i1 [[CMP]]
1292+
;
1293+
%fs = fsub float %x, %y
1294+
%cmp = fcmp ogt float %fs, 0.000000e+00
1295+
ret i1 %cmp
1296+
}
1297+
1298+
define i1 @fcmp_fsub_const_extra(float %x, float %y) {
1299+
; CHECK-LABEL: @fcmp_fsub_const_extra(
1300+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1301+
; CHECK-NEXT: call void @use(float [[FS]])
1302+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[FS]], 0.000000e+00
1303+
; CHECK-NEXT: ret i1 [[CMP]]
1304+
;
1305+
%fs = fsub float %x, %y
1306+
call void @use(float %fs)
1307+
%cmp = fcmp ogt float %fs, 0.000000e+00
1308+
ret i1 %cmp
1309+
}

0 commit comments

Comments
 (0)