Skip to content

Commit e9288bd

Browse files
karouzakispdtcxzyw
andauthored
Looks correct
Over-approximation fixed Co-authored-by: Yingwei Zheng <[email protected]>
1 parent 27e434a commit e9288bd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llvm/lib/Analysis/DemandedBits.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ void DemandedBits::determineLiveOperandBits(
8383
AB = APInt::getZero(BitWidth);
8484
uint64_t LoopRange = Max - Min;
8585
APInt Mask = AOut;
86+
APInt Shifted = AOut; // AOut | (AOut << 1) | ... | (AOut << (ShiftAmnt - 1)
8687
for (unsigned ShiftAmnt = 1; ShiftAmnt <= LoopRange; ShiftAmnt <<= 1) {
87-
APInt Shifted = ShiftF(Mask, ShiftAmnt);
88-
Mask |= Shifted;
88+
if (LoopRange & ShiftAmnt) {
89+
// Account for (LoopRange - ShiftAmnt, LoopRange]
90+
Mask |= ShiftF(Shifted, LoopRange - ShiftAmnt + 1);
91+
// Clears the low bit.
92+
LoopRange -= ShiftAmnt;
93+
}
94+
// [0, ShiftAmnt) -> [0, ShiftAmnt * 2)
95+
Shifted |= ShiftF(Shifted, ShiftAmnt);
8996
}
9097
AB = ShiftF(Mask, Min);
9198
};

0 commit comments

Comments
 (0)