Skip to content

Commit 2d18613

Browse files
committed
[IR] Use llvm::invert_fabs
1 parent 2c6cad1 commit 2d18613

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ template <typename ContextT> class GenericFloatingPointPredicateUtils {
135135
if (Mode.Input != DenormalMode::IEEE)
136136
return {Invalid, fcAllFlags, fcAllFlags};
137137

138+
auto ExactClass = [IsFabs, Src](FPClassTest Mask) {
139+
if (IsFabs)
140+
Mask = llvm::inverse_fabs(Mask);
141+
return exactClass(Src, Mask);
142+
};
143+
138144
switch (Pred) {
139145
case FCmpInst::FCMP_OEQ: // Match x == 0.0
140146
return exactClass(Src, fcZero);
@@ -151,37 +157,21 @@ template <typename ContextT> class GenericFloatingPointPredicateUtils {
151157
case FCmpInst::FCMP_UNO:
152158
return exactClass(Src, fcNan);
153159
case FCmpInst::FCMP_OGT: // x > 0
154-
if (IsFabs)
155-
return exactClass(Src, fcSubnormal | fcNormal | fcInf);
156-
return exactClass(Src, fcPosSubnormal | fcPosNormal | fcPosInf);
160+
return ExactClass(fcPosSubnormal | fcPosNormal | fcPosInf);
157161
case FCmpInst::FCMP_UGT: // isnan(x) || x > 0
158-
if (IsFabs)
159-
return exactClass(Src, fcSubnormal | fcNormal | fcInf | fcNan);
160-
return exactClass(Src, fcPosSubnormal | fcPosNormal | fcPosInf | fcNan);
162+
return ExactClass(fcPosSubnormal | fcPosNormal | fcPosInf | fcNan);
161163
case FCmpInst::FCMP_OGE: // x >= 0
162-
if (IsFabs)
163-
return exactClass(Src, ~fcNan);
164-
return exactClass(Src, fcPositive | fcNegZero);
164+
return ExactClass(fcPositive | fcNegZero);
165165
case FCmpInst::FCMP_UGE: // isnan(x) || x >= 0
166-
if (IsFabs)
167-
return exactClass(Src, fcAllFlags);
168-
return exactClass(Src, fcPositive | fcNegZero | fcNan);
166+
return ExactClass(fcPositive | fcNegZero | fcNan);
169167
case FCmpInst::FCMP_OLT: // x < 0
170-
if (IsFabs)
171-
return exactClass(Src, fcNone);
172-
return exactClass(Src, fcNegSubnormal | fcNegNormal | fcNegInf);
168+
return ExactClass(fcNegSubnormal | fcNegNormal | fcNegInf);
173169
case FCmpInst::FCMP_ULT: // isnan(x) || x < 0
174-
if (IsFabs)
175-
return exactClass(Src, fcNan);
176-
return exactClass(Src, fcNegSubnormal | fcNegNormal | fcNegInf | fcNan);
170+
return ExactClass(fcNegSubnormal | fcNegNormal | fcNegInf | fcNan);
177171
case FCmpInst::FCMP_OLE: // x <= 0
178-
if (IsFabs)
179-
return exactClass(Src, fcZero);
180-
return exactClass(Src, fcNegative | fcPosZero);
172+
return ExactClass(fcNegative | fcPosZero);
181173
case FCmpInst::FCMP_ULE: // isnan(x) || x <= 0
182-
if (IsFabs)
183-
return exactClass(Src, fcZero | fcNan);
184-
return exactClass(Src, fcNegative | fcPosZero | fcNan);
174+
return ExactClass(fcNegative | fcPosZero | fcNan);
185175
default:
186176
llvm_unreachable("all compare types are handled");
187177
}

0 commit comments

Comments
 (0)