Skip to content

Commit 6f619c9

Browse files
authored
[InstSimplify] Only handle canonical forms in simplifyAndOrOfFCmps. NFC. (#98136)
This patch avoids calling `isKnownNeverNaN` in `simplifyAndOrOfFCmps` since `fcmp ord/uno X, NNAN` will be canonicalized into `fcmp ord/uno X, 0.0` in InstCombine.
1 parent 869ac40 commit 6f619c9

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,14 +1872,11 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
18721872
if ((PredL == FCmpInst::FCMP_ORD || PredL == FCmpInst::FCMP_UNO) &&
18731873
((FCmpInst::isOrdered(PredR) && IsAnd) ||
18741874
(FCmpInst::isUnordered(PredR) && !IsAnd))) {
1875-
// (fcmp ord X, NNAN) & (fcmp o** X, Y) --> fcmp o** X, Y
1876-
// (fcmp uno X, NNAN) & (fcmp o** X, Y) --> false
1877-
// (fcmp uno X, NNAN) | (fcmp u** X, Y) --> fcmp u** X, Y
1878-
// (fcmp ord X, NNAN) | (fcmp u** X, Y) --> true
1879-
if (((LHS1 == RHS0 || LHS1 == RHS1) &&
1880-
isKnownNeverNaN(LHS0, /*Depth=*/0, Q)) ||
1881-
((LHS0 == RHS0 || LHS0 == RHS1) &&
1882-
isKnownNeverNaN(LHS1, /*Depth=*/0, Q)))
1875+
// (fcmp ord X, 0) & (fcmp o** X, Y) --> fcmp o** X, Y
1876+
// (fcmp uno X, 0) & (fcmp o** X, Y) --> false
1877+
// (fcmp uno X, 0) | (fcmp u** X, Y) --> fcmp u** X, Y
1878+
// (fcmp ord X, 0) | (fcmp u** X, Y) --> true
1879+
if ((LHS0 == RHS0 || LHS0 == RHS1) && match(LHS1, m_PosZeroFP()))
18831880
return FCmpInst::isOrdered(PredL) == FCmpInst::isOrdered(PredR)
18841881
? static_cast<Value *>(RHS)
18851882
: ConstantInt::getBool(LHS->getType(), !IsAnd);
@@ -1888,14 +1885,11 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
18881885
if ((PredR == FCmpInst::FCMP_ORD || PredR == FCmpInst::FCMP_UNO) &&
18891886
((FCmpInst::isOrdered(PredL) && IsAnd) ||
18901887
(FCmpInst::isUnordered(PredL) && !IsAnd))) {
1891-
// (fcmp o** X, Y) & (fcmp ord X, NNAN) --> fcmp o** X, Y
1892-
// (fcmp o** X, Y) & (fcmp uno X, NNAN) --> false
1893-
// (fcmp u** X, Y) | (fcmp uno X, NNAN) --> fcmp u** X, Y
1894-
// (fcmp u** X, Y) | (fcmp ord X, NNAN) --> true
1895-
if (((RHS1 == LHS0 || RHS1 == LHS1) &&
1896-
isKnownNeverNaN(RHS0, /*Depth=*/0, Q)) ||
1897-
((RHS0 == LHS0 || RHS0 == LHS1) &&
1898-
isKnownNeverNaN(RHS1, /*Depth=*/0, Q)))
1888+
// (fcmp o** X, Y) & (fcmp ord X, 0) --> fcmp o** X, Y
1889+
// (fcmp o** X, Y) & (fcmp uno X, 0) --> false
1890+
// (fcmp u** X, Y) | (fcmp uno X, 0) --> fcmp u** X, Y
1891+
// (fcmp u** X, Y) | (fcmp ord X, 0) --> true
1892+
if ((RHS0 == LHS0 || RHS0 == LHS1) && match(RHS1, m_PosZeroFP()))
18991893
return FCmpInst::isOrdered(PredL) == FCmpInst::isOrdered(PredR)
19001894
? static_cast<Value *>(LHS)
19011895
: ConstantInt::getBool(LHS->getType(), !IsAnd);

llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
33

44
; Cycle through commuted variants where one operand of fcmp ord/uno is
55
; known not-a-NAN and the other is repeated in the logically-connected fcmp.

0 commit comments

Comments
 (0)