Skip to content

Commit c13c7d7

Browse files
author
anoopkg6
committed
Fix Windows build failure because of __builtin_clz.
1 parent 140bd6a commit c13c7d7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8926,18 +8926,33 @@ bool SystemZTargetLowering::combineCCMask(SDValue &CCReg, int &CCValid,
89268926
return SmallVector<int, 4>();
89278927
return CCVals;
89288928
};
8929+
const auto getMSBPosSet = [](unsigned int Mask) {
8930+
int NumBits = std::numeric_limits<unsigned int>::digits;
8931+
int count = 0;
8932+
// Keep target search space to the left.
8933+
while (NumBits > 0) {
8934+
NumBits /= 2;
8935+
// Upper half zeros.
8936+
if (!(Mask >> NumBits)) {
8937+
count += NumBits;
8938+
// Search lower half.
8939+
Mask <<= NumBits;
8940+
}
8941+
}
8942+
return count;
8943+
};
8944+
89298945
if (CCNode->getOpcode() == SystemZISD::TM) {
89308946
if (CCValid != SystemZ::CCMASK_TM)
89318947
return false;
8932-
const auto emulateTMCCMask = [](int CCVal, int Mask) {
8948+
const auto emulateTMCCMask = [&](int CCVal, int Mask) {
89338949
if (!Mask)
8934-
return -1;
8950+
return std::numeric_limits<unsigned int>::digits;
89358951
int Result = CCVal & Mask;
89368952
bool AllOnes = Result == Mask;
89378953
bool AllZeros = Result == 0;
89388954
bool MixedZerosOnes = (!AllOnes && !AllZeros);
8939-
int MSBPos = (std::numeric_limits<unsigned int>::digits - 1) -
8940-
__builtin_clz(static_cast<unsigned int>(Mask));
8955+
int MSBPos = getMSBPosSet(static_cast<unsigned int>(Mask));
89418956
bool IsLeftMostBitSet = (Result & (1 << MSBPos)) != 0;
89428957
return AllOnes ? 3
89438958
: AllZeros ? 0

0 commit comments

Comments
 (0)