Skip to content

Commit a950fba

Browse files
committed
FIXME: or when the offset was add nuw
Add add-nuw detection
1 parent 3799bfb commit a950fba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,10 +3020,14 @@ bool LoopIdiomRecognize::recognizeShiftUntilZero() {
30203020
{ValNumActiveBitsOffset, Start},
30213021
/*FMFSource=*/nullptr, "iv.final");
30223022

3023+
// Check if the offset was added with NUW flag
3024+
bool OffsetAddHasNUW = OffsetIsZero;
3025+
if (auto *OffsetAddInst = dyn_cast<BinaryOperator>(ValNumActiveBitsOffset))
3026+
OffsetAddHasNUW |= OffsetAddInst->hasNoUnsignedWrap();
3027+
30233028
auto *LoopBackedgeTakenCount = cast<Instruction>(Builder.CreateSub(
30243029
IVFinal, Start, CurLoop->getName() + ".backedgetakencount",
3025-
/*HasNUW=*/OffsetIsZero, /*HasNSW=*/true));
3026-
// FIXME: or when the offset was `add nuw`
3030+
/*HasNUW=*/OffsetAddHasNUW, /*HasNSW=*/true));
30273031

30283032
// We know loop's backedge-taken count, but what's loop's trip count?
30293033
Value *LoopTripCount =

0 commit comments

Comments
 (0)