Skip to content

Commit b5aeeee

Browse files
committed
Add a recursive depth limit.
1 parent 4574283 commit b5aeeee

File tree

1 file changed

+29
-53
lines changed

1 file changed

+29
-53
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#include <bitset>
6464
#include <cctype>
6565
#include <numeric>
66-
#include <tuple>
6766
using namespace llvm;
6867

6968
#define DEBUG_TYPE "x86-isel"
@@ -44746,59 +44745,39 @@ bool X86TargetLowering::isSplatValueForTargetNode(SDValue Op,
4474644745

4474744746
// Helper to peek through bitops/trunc/setcc to determine size of source vector.
4474844747
// Allows combineBitcastvxi1 to determine what size vector generated a <X x i1>.
44749-
static bool
44750-
checkBitcastSrcVectorSize(SDValue Src, unsigned Size, bool AllowTruncate,
44751-
std::map<std::tuple<SDValue, unsigned, bool>, bool>
44752-
&BitcastSrcVectorSizeMap) {
44753-
auto Tp = std::make_tuple(Src, Size, AllowTruncate);
44754-
if (BitcastSrcVectorSizeMap.count(Tp))
44755-
return BitcastSrcVectorSizeMap[Tp];
44748+
static bool checkBitcastSrcVectorSize(SDValue Src, unsigned Size,
44749+
bool AllowTruncate, unsigned Depth) {
44750+
// Limit recursion.
44751+
if (Depth >= SelectionDAG::MaxRecursionDepth)
44752+
return false;
4475644753
switch (Src.getOpcode()) {
4475744754
case ISD::TRUNCATE:
44758-
if (!AllowTruncate) {
44759-
BitcastSrcVectorSizeMap[Tp] = false;
44755+
if (!AllowTruncate)
4476044756
return false;
44761-
}
4476244757
[[fallthrough]];
44763-
case ISD::SETCC: {
44764-
auto Ret = Src.getOperand(0).getValueSizeInBits() == Size;
44765-
BitcastSrcVectorSizeMap[Tp] = Ret;
44766-
return Ret;
44767-
}
44768-
case ISD::FREEZE: {
44769-
auto Ret = checkBitcastSrcVectorSize(Src.getOperand(0), Size, AllowTruncate,
44770-
BitcastSrcVectorSizeMap);
44771-
BitcastSrcVectorSizeMap[Tp] = Ret;
44772-
return Ret;
44773-
}
44758+
case ISD::SETCC:
44759+
return Src.getOperand(0).getValueSizeInBits() == Size;
44760+
case ISD::FREEZE:
44761+
return checkBitcastSrcVectorSize(Src.getOperand(0), Size, AllowTruncate,
44762+
Depth + 1);
4477444763
case ISD::AND:
4477544764
case ISD::XOR:
44776-
case ISD::OR: {
44777-
auto Ret1 = checkBitcastSrcVectorSize(
44778-
Src.getOperand(0), Size, AllowTruncate, BitcastSrcVectorSizeMap);
44779-
auto Ret2 = checkBitcastSrcVectorSize(
44780-
Src.getOperand(1), Size, AllowTruncate, BitcastSrcVectorSizeMap);
44781-
BitcastSrcVectorSizeMap[Tp] = Ret1 && Ret2;
44782-
return Ret1 && Ret2;
44783-
}
44765+
case ISD::OR:
44766+
return checkBitcastSrcVectorSize(Src.getOperand(0), Size, AllowTruncate,
44767+
Depth + 1) &&
44768+
checkBitcastSrcVectorSize(Src.getOperand(1), Size, AllowTruncate,
44769+
Depth + 1);
4478444770
case ISD::SELECT:
44785-
case ISD::VSELECT: {
44786-
auto Ret1 = checkBitcastSrcVectorSize(
44787-
Src.getOperand(1), Size, AllowTruncate, BitcastSrcVectorSizeMap);
44788-
auto Ret2 = checkBitcastSrcVectorSize(
44789-
Src.getOperand(2), Size, AllowTruncate, BitcastSrcVectorSizeMap);
44790-
auto Ret3 = Src.getOperand(0).getScalarValueSizeInBits() == 1;
44791-
BitcastSrcVectorSizeMap[Tp] = Ret1 && Ret2 && Ret3;
44792-
return Ret1 && Ret2 && Ret3;
44793-
}
44794-
case ISD::BUILD_VECTOR: {
44795-
auto Ret = ISD::isBuildVectorAllZeros(Src.getNode()) ||
44796-
ISD::isBuildVectorAllOnes(Src.getNode());
44797-
BitcastSrcVectorSizeMap[Tp] = Ret;
44798-
return Ret;
44799-
}
44771+
case ISD::VSELECT:
44772+
return Src.getOperand(0).getScalarValueSizeInBits() == 1 &&
44773+
checkBitcastSrcVectorSize(Src.getOperand(1), Size, AllowTruncate,
44774+
Depth + 1) &&
44775+
checkBitcastSrcVectorSize(Src.getOperand(2), Size, AllowTruncate,
44776+
Depth + 1);
44777+
case ISD::BUILD_VECTOR:
44778+
return ISD::isBuildVectorAllZeros(Src.getNode()) ||
44779+
ISD::isBuildVectorAllOnes(Src.getNode());
4480044780
}
44801-
BitcastSrcVectorSizeMap[Tp] = false;
4480244781
return false;
4480344782
}
4480444783

@@ -44954,7 +44933,6 @@ static SDValue combineBitcastvxi1(SelectionDAG &DAG, EVT VT, SDValue Src,
4495444933
// (v16i8 shuffle <0,2,4,6,8,10,12,14,u,u,...,u> (v16i8 bitcast t0), undef)
4495544934
MVT SExtVT;
4495644935
bool PropagateSExt = false;
44957-
std::map<std::tuple<SDValue, unsigned, bool>, bool> BitcastSrcVectorSizeMap;
4495844936
switch (SrcVT.getSimpleVT().SimpleTy) {
4495944937
default:
4496044938
return SDValue();
@@ -44966,8 +44944,7 @@ static SDValue combineBitcastvxi1(SelectionDAG &DAG, EVT VT, SDValue Src,
4496644944
// For cases such as (i4 bitcast (v4i1 setcc v4i64 v1, v2))
4496744945
// sign-extend to a 256-bit operation to avoid truncation.
4496844946
if (Subtarget.hasAVX() &&
44969-
checkBitcastSrcVectorSize(Src, 256, Subtarget.hasAVX2(),
44970-
BitcastSrcVectorSizeMap)) {
44947+
checkBitcastSrcVectorSize(Src, 256, Subtarget.hasAVX2(), 0)) {
4497144948
SExtVT = MVT::v4i64;
4497244949
PropagateSExt = true;
4497344950
}
@@ -44979,9 +44956,8 @@ static SDValue combineBitcastvxi1(SelectionDAG &DAG, EVT VT, SDValue Src,
4497944956
// If the setcc operand is 128-bit, prefer sign-extending to 128-bit over
4498044957
// 256-bit because the shuffle is cheaper than sign extending the result of
4498144958
// the compare.
44982-
if (Subtarget.hasAVX() &&
44983-
(checkBitcastSrcVectorSize(Src, 256, true, BitcastSrcVectorSizeMap) ||
44984-
checkBitcastSrcVectorSize(Src, 512, true, BitcastSrcVectorSizeMap))) {
44959+
if (Subtarget.hasAVX() && (checkBitcastSrcVectorSize(Src, 256, true, 0) ||
44960+
checkBitcastSrcVectorSize(Src, 512, true, 0))) {
4498544961
SExtVT = MVT::v8i32;
4498644962
PropagateSExt = true;
4498744963
}
@@ -45006,7 +44982,7 @@ static SDValue combineBitcastvxi1(SelectionDAG &DAG, EVT VT, SDValue Src,
4500644982
break;
4500744983
}
4500844984
// Split if this is a <64 x i8> comparison result.
45009-
if (checkBitcastSrcVectorSize(Src, 512, false, BitcastSrcVectorSizeMap)) {
44985+
if (checkBitcastSrcVectorSize(Src, 512, false, 0)) {
4501044986
SExtVT = MVT::v64i8;
4501144987
break;
4501244988
}

0 commit comments

Comments
 (0)