Skip to content

Commit 2d32ffe

Browse files
committed
Modifies code and updates relevant tests
1 parent 9cad265 commit 2d32ffe

File tree

2 files changed

+192
-41
lines changed

2 files changed

+192
-41
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7973,11 +7973,36 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
79737973
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
79747974
switch (LHSI->getOpcode()) {
79757975
case Instruction::FSub:
7976-
if ((Pred == FCmpInst::FCMP_OGT || Pred == FCmpInst::FCMP_OLT ||
7977-
Pred == FCmpInst::FCMP_ONE) &&
7978-
match(RHSC, m_AnyZeroFP()) &&
7979-
match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
7980-
return new FCmpInst(Pred, X, Y);
7976+
switch (Pred) {
7977+
default:
7978+
break;
7979+
case FCmpInst::FCMP_UGT:
7980+
case FCmpInst::FCMP_ULT:
7981+
case FCmpInst::FCMP_UNE:
7982+
case FCmpInst::FCMP_OEQ:
7983+
case FCmpInst::FCMP_OGE:
7984+
case FCmpInst::FCMP_OLE: {
7985+
BinaryOperator *SubI = cast<BinaryOperator>(LHSI);
7986+
if (!computeKnownFPClass(SubI->getOperand(0), SubI->getFastMathFlags(),
7987+
fcInf, LHSI, 0)
7988+
.isKnownNeverInfinity() &&
7989+
!computeKnownFPClass(SubI->getOperand(1), SubI->getFastMathFlags(),
7990+
fcInf, LHSI, 0)
7991+
.isKnownNeverInfinity())
7992+
break;
7993+
}
7994+
LLVM_FALLTHROUGH;
7995+
case FCmpInst::FCMP_OGT:
7996+
case FCmpInst::FCMP_OLT:
7997+
case FCmpInst::FCMP_ONE:
7998+
case FCmpInst::FCMP_UEQ:
7999+
case FCmpInst::FCMP_UGE:
8000+
case FCmpInst::FCMP_ULE:
8001+
if (match(RHSC, m_AnyZeroFP()) &&
8002+
match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
8003+
return new FCmpInst(Pred, X, Y);
8004+
break;
8005+
}
79818006
break;
79828007
case Instruction::PHI:
79838008
if (Instruction *NV = foldOpIntoPhi(I, cast<PHINode>(LHSI)))

llvm/test/Transforms/InstCombine/fcmp.ll

Lines changed: 162 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,38 +1315,164 @@ define i1 @fcmp_one_fsub_const(float %x, float %y) {
13151315
ret i1 %cmp
13161316
}
13171317

1318-
define <8 x i1> @fcmp_vec_ogt_fsub_const(<8 x float> %x, <8 x float> %y) {
1319-
; CHECK-LABEL: @fcmp_vec_ogt_fsub_const(
1320-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
1318+
define i1 @fcmp_oeq_fsub_const(float %x, float %y) {
1319+
; CHECK-LABEL: @fcmp_oeq_fsub_const(
1320+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1321+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[FS]], 0.000000e+00
1322+
; CHECK-NEXT: ret i1 [[CMP]]
1323+
;
1324+
%fs = fsub float %x, %y
1325+
%cmp = fcmp oeq float %fs, 0.000000e+00
1326+
ret i1 %cmp
1327+
}
1328+
1329+
define i1 @fcmp_oge_fsub_const(float %x, float %y) {
1330+
; CHECK-LABEL: @fcmp_oge_fsub_const(
1331+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1332+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[FS]], 0.000000e+00
1333+
; CHECK-NEXT: ret i1 [[CMP]]
1334+
;
1335+
%fs = fsub float %x, %y
1336+
%cmp = fcmp oge float %fs, 0.000000e+00
1337+
ret i1 %cmp
1338+
}
1339+
1340+
define i1 @fcmp_ole_fsub_const(float %x, float %y) {
1341+
; CHECK-LABEL: @fcmp_ole_fsub_const(
1342+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1343+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[FS]], 0.000000e+00
1344+
; CHECK-NEXT: ret i1 [[CMP]]
1345+
;
1346+
%fs = fsub float %x, %y
1347+
%cmp = fcmp ole float %fs, 0.000000e+00
1348+
ret i1 %cmp
1349+
}
1350+
1351+
define i1 @fcmp_ueq_fsub_const(float %x, float %y) {
1352+
; CHECK-LABEL: @fcmp_ueq_fsub_const(
1353+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[X:%.*]], [[Y:%.*]]
1354+
; CHECK-NEXT: ret i1 [[CMP]]
1355+
;
1356+
%fs = fsub float %x, %y
1357+
%cmp = fcmp ueq float %fs, 0.000000e+00
1358+
ret i1 %cmp
1359+
}
1360+
1361+
define i1 @fcmp_uge_fsub_const(float %x, float %y) {
1362+
; CHECK-LABEL: @fcmp_uge_fsub_const(
1363+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[X:%.*]], [[Y:%.*]]
1364+
; CHECK-NEXT: ret i1 [[CMP]]
1365+
;
1366+
%fs = fsub float %x, %y
1367+
%cmp = fcmp uge float %fs, 0.000000e+00
1368+
ret i1 %cmp
1369+
}
1370+
1371+
define i1 @fcmp_ule_fsub_const(float %x, float %y) {
1372+
; CHECK-LABEL: @fcmp_ule_fsub_const(
1373+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[X:%.*]], [[Y:%.*]]
1374+
; CHECK-NEXT: ret i1 [[CMP]]
1375+
;
1376+
%fs = fsub float %x, %y
1377+
%cmp = fcmp ule float %fs, 0.000000e+00
1378+
ret i1 %cmp
1379+
}
1380+
1381+
define i1 @fcmp_ugt_fsub_const(float %x, float %y) {
1382+
; CHECK-LABEL: @fcmp_ugt_fsub_const(
1383+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1384+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[FS]], 0.000000e+00
1385+
; CHECK-NEXT: ret i1 [[CMP]]
1386+
;
1387+
%fs = fsub float %x, %y
1388+
%cmp = fcmp ugt float %fs, 0.000000e+00
1389+
ret i1 %cmp
1390+
}
1391+
1392+
define i1 @fcmp_ult_fsub_const(float %x, float %y) {
1393+
; CHECK-LABEL: @fcmp_ult_fsub_const(
1394+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1395+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[FS]], 0.000000e+00
1396+
; CHECK-NEXT: ret i1 [[CMP]]
1397+
;
1398+
%fs = fsub float %x, %y
1399+
%cmp = fcmp ult float %fs, 0.000000e+00
1400+
ret i1 %cmp
1401+
}
1402+
1403+
define i1 @fcmp_une_fsub_const(float %x, float %y) {
1404+
; CHECK-LABEL: @fcmp_une_fsub_const(
1405+
; CHECK-NEXT: [[FS:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
1406+
; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[FS]], 0.000000e+00
1407+
; CHECK-NEXT: ret i1 [[CMP]]
1408+
;
1409+
%fs = fsub float %x, %y
1410+
%cmp = fcmp une float %fs, 0.000000e+00
1411+
ret i1 %cmp
1412+
}
1413+
1414+
define <8 x i1> @fcmp_vec_uge_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1415+
; CHECK-LABEL: @fcmp_vec_uge_fast_fsub_const(
1416+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uge <8 x float> [[X:%.*]], [[Y:%.*]]
13211417
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13221418
;
1323-
%fs = fsub <8 x float> %x, %y
1324-
%cmp = fcmp ogt <8 x float> %fs, zeroinitializer
1419+
%fs = fsub fast <8 x float> %x, %y
1420+
%cmp = fcmp uge <8 x float> %fs, zeroinitializer
13251421
ret <8 x i1> %cmp
13261422
}
13271423

1328-
define <8 x i1> @fcmp_vec_olt_fsub_const(<8 x float> %x, <8 x float> %y) {
1329-
; CHECK-LABEL: @fcmp_vec_olt_fsub_const(
1330-
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
1424+
define <8 x i1> @fcmp_vec_ule_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1425+
; CHECK-LABEL: @fcmp_vec_ule_fast_fsub_const(
1426+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ule <8 x float> [[X:%.*]], [[Y:%.*]]
13311427
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13321428
;
1333-
%fs = fsub <8 x float> %x, %y
1334-
%cmp = fcmp olt <8 x float> %fs, zeroinitializer
1429+
%fs = fsub fast <8 x float> %x, %y
1430+
%cmp = fcmp ule <8 x float> %fs, zeroinitializer
13351431
ret <8 x i1> %cmp
13361432
}
13371433

1338-
define <8 x i1> @fcmp_vec_one_fsub_const(<8 x float> %x, <8 x float> %y) {
1339-
; CHECK-LABEL: @fcmp_vec_one_fsub_const(
1340-
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
1434+
define <8 x i1> @fcmp_vec_ueq_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1435+
; CHECK-LABEL: @fcmp_vec_ueq_fast_fsub_const(
1436+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq <8 x float> [[X:%.*]], [[Y:%.*]]
13411437
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13421438
;
1343-
%fs = fsub <8 x float> %x, %y
1344-
%cmp = fcmp one <8 x float> %fs, zeroinitializer
1439+
%fs = fsub fast <8 x float> %x, %y
1440+
%cmp = fcmp ueq <8 x float> %fs, zeroinitializer
13451441
ret <8 x i1> %cmp
13461442
}
13471443

1348-
define <8 x i1> @fcmp_vec_ogt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1349-
; CHECK-LABEL: @fcmp_vec_ogt_fm_fsub_const(
1444+
define <8 x i1> @fcmp_vec_oge_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1445+
; CHECK-LABEL: @fcmp_vec_oge_fast_fsub_const(
1446+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge <8 x float> [[X:%.*]], [[Y:%.*]]
1447+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1448+
;
1449+
%fs = fsub fast <8 x float> %x, %y
1450+
%cmp = fcmp oge <8 x float> %fs, zeroinitializer
1451+
ret <8 x i1> %cmp
1452+
}
1453+
1454+
define <8 x i1> @fcmp_vec_ole_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1455+
; CHECK-LABEL: @fcmp_vec_ole_fast_fsub_const(
1456+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ole <8 x float> [[X:%.*]], [[Y:%.*]]
1457+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1458+
;
1459+
%fs = fsub fast <8 x float> %x, %y
1460+
%cmp = fcmp ole <8 x float> %fs, zeroinitializer
1461+
ret <8 x i1> %cmp
1462+
}
1463+
1464+
define <8 x i1> @fcmp_vec_oeq_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1465+
; CHECK-LABEL: @fcmp_vec_oeq_fast_fsub_const(
1466+
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq <8 x float> [[X:%.*]], [[Y:%.*]]
1467+
; CHECK-NEXT: ret <8 x i1> [[CMP]]
1468+
;
1469+
%fs = fsub fast <8 x float> %x, %y
1470+
%cmp = fcmp oeq <8 x float> %fs, zeroinitializer
1471+
ret <8 x i1> %cmp
1472+
}
1473+
1474+
define <8 x i1> @fcmp_vec_ogt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1475+
; CHECK-LABEL: @fcmp_vec_ogt_fast_fsub_const(
13501476
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
13511477
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13521478
;
@@ -1355,8 +1481,8 @@ define <8 x i1> @fcmp_vec_ogt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
13551481
ret <8 x i1> %cmp
13561482
}
13571483

1358-
define <8 x i1> @fcmp_vec_olt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1359-
; CHECK-LABEL: @fcmp_vec_olt_fm_fsub_const(
1484+
define <8 x i1> @fcmp_vec_olt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1485+
; CHECK-LABEL: @fcmp_vec_olt_fast_fsub_const(
13601486
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
13611487
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13621488
;
@@ -1365,8 +1491,8 @@ define <8 x i1> @fcmp_vec_olt_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
13651491
ret <8 x i1> %cmp
13661492
}
13671493

1368-
define <8 x i1> @fcmp_vec_one_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
1369-
; CHECK-LABEL: @fcmp_vec_one_fm_fsub_const(
1494+
define <8 x i1> @fcmp_vec_one_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1495+
; CHECK-LABEL: @fcmp_vec_one_fast_fsub_const(
13701496
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
13711497
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13721498
;
@@ -1375,32 +1501,32 @@ define <8 x i1> @fcmp_vec_one_fm_fsub_const(<8 x float> %x, <8 x float> %y) {
13751501
ret <8 x i1> %cmp
13761502
}
13771503

1378-
define <8 x i1> @ffcmp_vec_ogt_fsub_const(<8 x float> %x, <8 x float> %y) {
1379-
; CHECK-LABEL: @ffcmp_vec_ogt_fsub_const(
1380-
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <8 x float> [[X:%.*]], [[Y:%.*]]
1504+
define <8 x i1> @fcmp_vec_ugt_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1505+
; CHECK-LABEL: @fcmp_vec_ugt_fast_fsub_const(
1506+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt <8 x float> [[X:%.*]], [[Y:%.*]]
13811507
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13821508
;
1383-
%fs = fsub <8 x float> %x, %y
1384-
%cmp = fcmp fast ogt <8 x float> %fs, zeroinitializer
1509+
%fs = fsub fast <8 x float> %x, %y
1510+
%cmp = fcmp ugt <8 x float> %fs, zeroinitializer
13851511
ret <8 x i1> %cmp
13861512
}
13871513

1388-
define <8 x i1> @ffcmp_vec_olt_fsub_const(<8 x float> %x, <8 x float> %y) {
1389-
; CHECK-LABEL: @ffcmp_vec_olt_fsub_const(
1390-
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[X:%.*]], [[Y:%.*]]
1514+
define <8 x i1> @fcmp_vec_ult_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1515+
; CHECK-LABEL: @fcmp_vec_ult_fast_fsub_const(
1516+
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <8 x float> [[X:%.*]], [[Y:%.*]]
13911517
; CHECK-NEXT: ret <8 x i1> [[CMP]]
13921518
;
1393-
%fs = fsub <8 x float> %x, %y
1394-
%cmp = fcmp fast olt <8 x float> %fs, zeroinitializer
1519+
%fs = fsub fast <8 x float> %x, %y
1520+
%cmp = fcmp ult <8 x float> %fs, zeroinitializer
13951521
ret <8 x i1> %cmp
13961522
}
13971523

1398-
define <8 x i1> @ffcmp_vec_one_fsub_const(<8 x float> %x, <8 x float> %y) {
1399-
; CHECK-LABEL: @ffcmp_vec_one_fsub_const(
1400-
; CHECK-NEXT: [[CMP:%.*]] = fcmp one <8 x float> [[X:%.*]], [[Y:%.*]]
1524+
define <8 x i1> @fcmp_vec_une_fast_fsub_const(<8 x float> %x, <8 x float> %y) {
1525+
; CHECK-LABEL: @fcmp_vec_une_fast_fsub_const(
1526+
; CHECK-NEXT: [[CMP:%.*]] = fcmp une <8 x float> [[X:%.*]], [[Y:%.*]]
14011527
; CHECK-NEXT: ret <8 x i1> [[CMP]]
14021528
;
1403-
%fs = fsub <8 x float> %x, %y
1404-
%cmp = fcmp fast one <8 x float> %fs, zeroinitializer
1529+
%fs = fsub fast <8 x float> %x, %y
1530+
%cmp = fcmp une <8 x float> %fs, zeroinitializer
14051531
ret <8 x i1> %cmp
14061532
}

0 commit comments

Comments
 (0)