Skip to content

Commit 740ee52

Browse files
committed
Convert icmp->fcmp bounds tests to use significant bits instead of known bits
1 parent d17de96 commit 740ee52

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55721,9 +55721,9 @@ static SDValue combineVectorCompare(SDNode *N, SelectionDAG &DAG,
5572155721

5572255722
// Helper to determine if we can convert an integer comparison to a float
5572355723
// comparison byt casting the operands.
55724-
static std::optional<unsigned> CastIntSETCCtoFP(MVT VT, ISD::CondCode CC,
55725-
const KnownBits &LHS,
55726-
const KnownBits &RHS) {
55724+
static std::optional<unsigned>
55725+
CastIntSETCCtoFP(MVT VT, ISD::CondCode CC, unsigned NumSignificantBitsLHS,
55726+
unsigned NumSignificantBitsRHS) {
5572755727
MVT SVT = VT.getScalarType();
5572855728
assert(SVT == MVT::f32 && "Only tested for float so far");
5572955729
const fltSemantics &Sem = SelectionDAG::EVTToAPFloatSemantics(SVT);
@@ -55732,20 +55732,10 @@ static std::optional<unsigned> CastIntSETCCtoFP(MVT VT, ISD::CondCode CC,
5573255732

5573355733
// TODO: Handle bitcastable integers.
5573455734

55735-
// For cvt + signed compare we need:
55736-
// abs(lhs) < MaxConvertableCvt and abs(rhs) < MaxConvertableCvt
55737-
auto OpInAbsRange = [](const KnownBits &Known, const APInt &Bound) {
55738-
if (Known.isUnknown() ||
55739-
!KnownBits::slt(Known, KnownBits::makeConstant(Bound)) ||
55740-
!KnownBits::sgt(Known, KnownBits::makeConstant(-Bound)))
55741-
return false;
55742-
return true;
55743-
};
55744-
APInt MaxConvertableCvt = APInt::getOneBitSet(
55745-
SVT.getScalarSizeInBits(), APFloat::semanticsPrecision(Sem));
55746-
55747-
if (OpInAbsRange(RHS, MaxConvertableCvt) &&
55748-
OpInAbsRange(LHS, MaxConvertableCvt))
55735+
// For cvt + signed compare we need lhs and rhs to be exactly representable as
55736+
// a fp value.
55737+
unsigned FPPrec = APFloat::semanticsPrecision(Sem);
55738+
if (FPPrec >= NumSignificantBitsLHS && FPPrec >= NumSignificantBitsRHS)
5574955739
return ISD::SINT_TO_FP;
5575055740

5575155741
return std::nullopt;
@@ -56153,17 +56143,15 @@ static SDValue combineConcatVectorOps(const SDLoc &DL, MVT VT,
5615356143

5615456144
// Without AVX2, see if we can cast the values to v8f32 and use fcmp.
5615556145
// TODO: Handle v4f64 as well?
56156-
KnownBits KnownLHS(EltSizeInBits), KnownRHS(EltSizeInBits);
56157-
KnownLHS.One.setAllBits();
56158-
KnownRHS.One.setAllBits();
56159-
KnownLHS.Zero.setAllBits();
56160-
KnownRHS.Zero.setAllBits();
56146+
unsigned MaxSigBitsLHS = 0, MaxSigBitsRHS = 0;
5616156147
for (unsigned I = 0; I != NumOps; ++I) {
56162-
KnownBits LHS = DAG.computeKnownBits(Ops[I].getOperand(0));
56163-
KnownBits RHS = DAG.computeKnownBits(Ops[I].getOperand(1));
56164-
KnownLHS = KnownLHS.intersectWith(LHS);
56165-
KnownRHS = KnownRHS.intersectWith(RHS);
56166-
if (KnownLHS.isUnknown() && KnownRHS.isUnknown())
56148+
MaxSigBitsLHS =
56149+
std::max(MaxSigBitsLHS,
56150+
DAG.ComputeMaxSignificantBits(Ops[I].getOperand(0)));
56151+
MaxSigBitsRHS =
56152+
std::max(MaxSigBitsRHS,
56153+
DAG.ComputeMaxSignificantBits(Ops[I].getOperand(1)));
56154+
if (MaxSigBitsLHS == EltSizeInBits && MaxSigBitsRHS == EltSizeInBits)
5616756155
break;
5616856156
}
5616956157

@@ -56176,7 +56164,7 @@ static SDValue combineConcatVectorOps(const SDLoc &DL, MVT VT,
5617656164
MVT FpVT = VT.changeVectorElementType(FpSVT);
5617756165

5617856166
if (std::optional<unsigned> CastOpc =
56179-
CastIntSETCCtoFP(FpVT, ICC, KnownLHS, KnownRHS)) {
56167+
CastIntSETCCtoFP(FpVT, ICC, MaxSigBitsLHS, MaxSigBitsRHS)) {
5618056168
SDValue LHS = ConcatSubOperand(VT, Ops, 0);
5618156169
SDValue RHS = ConcatSubOperand(VT, Ops, 1);
5618256170
LHS = DAG.getNode(*CastOpc, DL, FpVT, LHS);

0 commit comments

Comments
 (0)