Skip to content

Commit e2cfa08

Browse files
committed
[CVP] Implement type narrowing for LShr
Implements type narrowing for LShr. The treatment is analogous to the type narrowing of UDiv. Since LShr is a relatively cheap instruction, the narrowing occurs only if the following conditions hold: i) all the users of the LShr instruction are already TruncInst; ii) the narrowing is carried out to the largest TruncInst following the LShr instruction. Additionally, the function optimizes the cases where the result of the LShr instruction is guaranteed to vanish or be equal to poison.
1 parent 0ce38dd commit e2cfa08

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,8 @@ static bool narrowLShr(BinaryOperator *LShr, LazyValueInfo *LVI) {
11031103

11041104
unsigned OrigWidth = RetTy->getScalarSizeInBits();
11051105
unsigned MaxActiveBitsInArg = ArgRange.getActiveBits();
1106-
uint64_t MinShiftValue64 = ShiftRange.getUnsignedMin().getZExtValue();
1107-
unsigned MinShiftValue =
1108-
MinShiftValue64 < std::numeric_limits<unsigned>::max()
1109-
? static_cast<unsigned>(MinShiftValue64)
1106+
unsigned MinShiftValue = ShiftRange.getUnsignedMin().getActiveBits() <= 32
1107+
? static_cast<unsigned>(ShiftRange.getUnsignedMin().getZExtValue())
11101108
: std::numeric_limits<unsigned>::max();
11111109

11121110
// First we deal with the cases where the result is guaranteed to vanish or be
@@ -1138,12 +1136,9 @@ static bool narrowLShr(BinaryOperator *LShr, LazyValueInfo *LVI) {
11381136
// width of the argument, we must make sure that the maximal possible value
11391137
// for the shift is larger than the new width after narrowing. Otherwise some
11401138
// shifts that originally vanish would result in poison after the narrowing.
1141-
uint64_t MaxShiftValue64 = ShiftRange.getUnsignedMax().getZExtValue();
1142-
unsigned MaxShiftValue =
1143-
MaxShiftValue64 < std::numeric_limits<unsigned>::max()
1144-
? static_cast<unsigned>(MaxShiftValue64)
1139+
unsigned MaxShiftValue = ShiftRange.getUnsignedMax().getActiveBits() <= 32
1140+
? static_cast<unsigned>(ShiftRange.getUnsignedMax().getZExtValue())
11451141
: std::numeric_limits<unsigned>::max();
1146-
11471142
if (OrigWidth <= MaxShiftValue)
11481143
return false;
11491144

0 commit comments

Comments
 (0)