diff options
author | 2021-04-11 15:38:15 +0300 | |
---|---|---|
committer | 2021-04-11 18:08:07 +0300 | |
commit | 005881e96e5fedab66f71cfa09558909d21e4a00 (patch) | |
tree | a20c6a6835c50a4a2cac5b74a3e173c181494b29 | |
parent | [NFC][LoopIdiom] left-shift-until-bittest: add small-bitwidth tests (diff) | |
download | llvm-project-005881e96e5fedab66f71cfa09558909d21e4a00.tar.gz llvm-project-005881e96e5fedab66f71cfa09558909d21e4a00.tar.bz2 llvm-project-005881e96e5fedab66f71cfa09558909d21e4a00.zip |
[LoopIdiom] left-shift-until-bittest: set all allowed no-wrap flags on add/sub
I've checked each one of these with alive2,
and this is both correct and precise.
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 20 | ||||
-rw-r--r-- | llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll | 212 |
2 files changed, 119 insertions, 113 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 3385bd6fee1b..d9b33face569 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -2133,6 +2133,7 @@ bool LoopIdiomRecognize::recognizeShiftUntilBitTest() { Intrinsic::ID IntrID = Intrinsic::ctlz; Type *Ty = X->getType(); + unsigned Bitwidth = Ty->getScalarSizeInBits(); TargetTransformInfo::TargetCostKind CostKind = TargetTransformInfo::TCK_SizeAndLatency; @@ -2169,18 +2170,22 @@ bool LoopIdiomRecognize::recognizeShiftUntilBitTest() { /*FMFSource=*/nullptr, XMasked->getName() + ".numleadingzeros"); Value *XMaskedNumActiveBits = Builder.CreateSub( ConstantInt::get(Ty, Ty->getScalarSizeInBits()), XMaskedNumLeadingZeros, - XMasked->getName() + ".numactivebits"); + XMasked->getName() + ".numactivebits", /*HasNUW=*/true, + /*HasNSW=*/Bitwidth != 2); Value *XMaskedLeadingOnePos = Builder.CreateAdd(XMaskedNumActiveBits, Constant::getAllOnesValue(Ty), - XMasked->getName() + ".leadingonepos"); + XMasked->getName() + ".leadingonepos", /*HasNUW=*/false, + /*HasNSW=*/Bitwidth > 2); Value *LoopBackedgeTakenCount = Builder.CreateSub( - BitPos, XMaskedLeadingOnePos, CurLoop->getName() + ".backedgetakencount"); + BitPos, XMaskedLeadingOnePos, CurLoop->getName() + ".backedgetakencount", + /*HasNUW=*/true, /*HasNSW=*/true); // We know loop's backedge-taken count, but what's loop's trip count? // Note that while NUW is always safe, while NSW is only for bitwidths != 2. Value *LoopTripCount = - Builder.CreateNUWAdd(LoopBackedgeTakenCount, ConstantInt::get(Ty, 1), - CurLoop->getName() + ".tripcount"); + Builder.CreateAdd(LoopBackedgeTakenCount, ConstantInt::get(Ty, 1), + CurLoop->getName() + ".tripcount", /*HasNUW=*/true, + /*HasNSW=*/Bitwidth != 2); // Step 2: Compute the recurrence's final value without a loop. @@ -2228,8 +2233,9 @@ bool LoopIdiomRecognize::recognizeShiftUntilBitTest() { // The induction itself. // Note that while NUW is always safe, while NSW is only for bitwidths != 2. Builder.SetInsertPoint(LoopHeaderBB->getTerminator()); - auto *IVNext = Builder.CreateNUWAdd(IV, ConstantInt::get(Ty, 1), - IV->getName() + ".next"); + auto *IVNext = + Builder.CreateAdd(IV, ConstantInt::get(Ty, 1), IV->getName() + ".next", + /*HasNUW=*/true, /*HasNSW=*/Bitwidth != 2); // The loop trip count check. auto *IVCheck = Builder.CreateICmpEQ(IVNext, LoopTripCount, diff --git a/llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll b/llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll index 94ce3a431604..6739601830d6 100644 --- a/llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll +++ b/llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll @@ -23,10 +23,10 @@ define i32 @p0_i32(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG17]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG17]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG17]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG17]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG17]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG17]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG17]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG17]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG17]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG17]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG17]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG17]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG17]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG18:![0-9]+]] @@ -40,7 +40,7 @@ define i32 @p0_i32(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META13:![0-9]+]], metadata !DIExpression()), !dbg [[DBG20]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG21:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META15:![0-9]+]], metadata !DIExpression()), !dbg [[DBG21]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG22:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG22:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG22]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG22]] ; LZCNT: end: @@ -91,10 +91,10 @@ define i16 @p1_i16(i16 %x, i16 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i16 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG33]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i16 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG33]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i16 @llvm.ctlz.i16(i16 [[X_MASKED]], i1 true), !dbg [[DBG33]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i16 16, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG33]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i16 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG33]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i16 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG33]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i16 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG33]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i16 16, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG33]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i16 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG33]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i16 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG33]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i16 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG33]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i16 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG33]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i16 [[X_CURR]], 1, !dbg [[DBG33]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG34:![0-9]+]] @@ -108,7 +108,7 @@ define i16 @p1_i16(i16 %x, i16 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META30:![0-9]+]], metadata !DIExpression()), !dbg [[DBG36]] ; LZCNT-NEXT: [[TMP1]] = shl i16 [[TMP0]], 1, !dbg [[DBG37:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i16 [[TMP1]], metadata [[META31:![0-9]+]], metadata !DIExpression()), !dbg [[DBG37]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i16 [[LOOP_IV]], 1, !dbg [[DBG38:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i16 [[LOOP_IV]], 1, !dbg [[DBG38:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i16 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG38]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG38]] ; LZCNT: end: @@ -159,10 +159,10 @@ define i32 @p2_different_liveout(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG48]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG48]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG48]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG48]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG48]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG48]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG48]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG48]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG48]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG48]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG48]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG48]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG48]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG49:![0-9]+]] @@ -176,7 +176,7 @@ define i32 @p2_different_liveout(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META45:![0-9]+]], metadata !DIExpression()), !dbg [[DBG51]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG52:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META46:![0-9]+]], metadata !DIExpression()), !dbg [[DBG52]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG53:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG53:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG53]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG53]] ; LZCNT: end: @@ -223,10 +223,10 @@ define void @p3_constant_mask_24thbit(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], 33554431, !dbg [[DBG61:![0-9]+]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG61]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG61]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG61]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 24, [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG61]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG61]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG61]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG61]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 24, [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG61]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG61]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG61]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X]], [[LOOP_TRIPCOUNT]], !dbg [[DBG61]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG62:![0-9]+]] @@ -240,7 +240,7 @@ define void @p3_constant_mask_24thbit(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META59:![0-9]+]], metadata !DIExpression()), !dbg [[DBG64]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG65:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META60:![0-9]+]], metadata !DIExpression()), !dbg [[DBG65]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG66:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG66:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG66]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG66]] ; LZCNT: end: @@ -291,10 +291,10 @@ define void @p4_constant_mask_15thbit(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], 65535, !dbg [[DBG76:![0-9]+]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG76]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG76]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG76]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 15, [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG76]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG76]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG76]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG76]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 15, [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG76]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG76]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG76]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X]], [[LOOP_TRIPCOUNT]], !dbg [[DBG76]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG77:![0-9]+]] @@ -308,7 +308,7 @@ define void @p4_constant_mask_15thbit(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META74:![0-9]+]], metadata !DIExpression()), !dbg [[DBG79]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG80:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META75:![0-9]+]], metadata !DIExpression()), !dbg [[DBG80]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG81:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG81:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG81]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG81]] ; LZCNT: end: @@ -364,10 +364,10 @@ define void @p5_nuw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG93]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG93]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG93]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG93]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG93]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG93]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG93]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG93]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG93]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG93]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG93]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl nuw i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG93]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl nuw i32 [[X]], [[LOOP_TRIPCOUNT]], !dbg [[DBG93]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG94:![0-9]+]] @@ -381,7 +381,7 @@ define void @p5_nuw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META90:![0-9]+]], metadata !DIExpression()), !dbg [[DBG96]] ; LZCNT-NEXT: [[TMP1]] = shl nuw i32 [[TMP0]], 1, !dbg [[DBG97:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META91:![0-9]+]], metadata !DIExpression()), !dbg [[DBG97]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG98:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG98:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG98]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG98]] ; LZCNT: end: @@ -438,10 +438,10 @@ define void @p6_nsw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG110]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG110]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG110]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG110]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG110]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG110]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG110]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG110]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG110]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG110]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG110]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl nsw i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG110]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl nsw i32 [[X]], [[LOOP_TRIPCOUNT]], !dbg [[DBG110]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG111:![0-9]+]] @@ -455,7 +455,7 @@ define void @p6_nsw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META107:![0-9]+]], metadata !DIExpression()), !dbg [[DBG113]] ; LZCNT-NEXT: [[TMP1]] = shl nsw i32 [[TMP0]], 1, !dbg [[DBG114:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META108:![0-9]+]], metadata !DIExpression()), !dbg [[DBG114]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG115:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG115:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG115]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG115]] ; LZCNT: end: @@ -512,10 +512,10 @@ define void @p7_nuwnsw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG127]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG127]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG127]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG127]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG127]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG127]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG127]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG127]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG127]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG127]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG127]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl nuw nsw i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG127]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl nuw nsw i32 [[X]], [[LOOP_TRIPCOUNT]], !dbg [[DBG127]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG128:![0-9]+]] @@ -529,7 +529,7 @@ define void @p7_nuwnsw(i32 %x, i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META124:![0-9]+]], metadata !DIExpression()), !dbg [[DBG130]] ; LZCNT-NEXT: [[TMP1]] = shl nuw nsw i32 [[TMP0]], 1, !dbg [[DBG131:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META125:![0-9]+]], metadata !DIExpression()), !dbg [[DBG131]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG132:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG132:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG132]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG132]] ; LZCNT: end: @@ -582,10 +582,10 @@ define void @p8_constant_mask_signbit_noncanonical(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-LABEL: @p8_constant_mask_signbit_noncanonical( ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true), !dbg [[DBG142:![0-9]+]] -; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG142]] -; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG142]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG142]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG142]] +; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG142]] +; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add nsw i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG142]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG142]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG142]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG142]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG142]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG143:![0-9]+]] @@ -599,7 +599,7 @@ define void @p8_constant_mask_signbit_noncanonical(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META140:![0-9]+]], metadata !DIExpression()), !dbg [[DBG145]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG146:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META141:![0-9]+]], metadata !DIExpression()), !dbg [[DBG146]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG147:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG147:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG147]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG147]] ; LZCNT: end: @@ -649,10 +649,10 @@ define void @p9_constant_mask_signbit_canonical(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-LABEL: @p9_constant_mask_signbit_canonical( ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true), !dbg [[DBG156:![0-9]+]] -; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG156]] -; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG156]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG156]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG156]] +; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG156]] +; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add nsw i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG156]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG156]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG156]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG156]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG156]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG157:![0-9]+]] @@ -664,7 +664,7 @@ define void @p9_constant_mask_signbit_canonical(i32 %x, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META154:![0-9]+]], metadata !DIExpression()), !dbg [[DBG158]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG159:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META155:![0-9]+]], metadata !DIExpression()), !dbg [[DBG159]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG160:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG160:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG160]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG160]] ; LZCNT: end: @@ -716,10 +716,10 @@ define void @p10_x_is_not_one(i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG172]] ; LZCNT-NEXT: [[DOTMASKED:%.*]] = and i32 2, [[BIT_MASK]], !dbg [[DBG172]] ; LZCNT-NEXT: [[DOTMASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[DOTMASKED]], i1 true), !dbg [[DBG172]] -; LZCNT-NEXT: [[DOTMASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[DOTMASKED_NUMLEADINGZEROS]], !dbg [[DBG172]] -; LZCNT-NEXT: [[DOTMASKED_LEADINGONEPOS:%.*]] = add i32 [[DOTMASKED_NUMACTIVEBITS]], -1, !dbg [[DBG172]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[DOTMASKED_LEADINGONEPOS]], !dbg [[DBG172]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG172]] +; LZCNT-NEXT: [[DOTMASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[DOTMASKED_NUMLEADINGZEROS]], !dbg [[DBG172]] +; LZCNT-NEXT: [[DOTMASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[DOTMASKED_NUMACTIVEBITS]], -1, !dbg [[DBG172]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[DOTMASKED_LEADINGONEPOS]], !dbg [[DBG172]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG172]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 2, [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG172]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG172]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG173:![0-9]+]] @@ -733,7 +733,7 @@ define void @p10_x_is_not_one(i32 %bit, i32* %p0, i32* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META169:![0-9]+]], metadata !DIExpression()), !dbg [[DBG175]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG176:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META170:![0-9]+]], metadata !DIExpression()), !dbg [[DBG176]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG177:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG177:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG177]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG177]] ; LZCNT: end: @@ -792,10 +792,10 @@ define i32 @p11(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG189]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG189]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG189]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG189]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG189]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG189]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG189]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG189]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG189]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG189]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG189]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG189]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG189]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG190:![0-9]+]] @@ -809,7 +809,7 @@ define i32 @p11(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META186:![0-9]+]], metadata !DIExpression()), !dbg [[DBG192]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG193:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META187:![0-9]+]], metadata !DIExpression()), !dbg [[DBG193]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG194:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG194:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG194]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG194]] ; LZCNT: end: @@ -860,10 +860,10 @@ define i32 @p12(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG204]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG204]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG204]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG204]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG204]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG204]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG204]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG204]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG204]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG204]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG204]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG204]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG204]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG205:![0-9]+]] @@ -877,7 +877,7 @@ define i32 @p12(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META201:![0-9]+]], metadata !DIExpression()), !dbg [[DBG207]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG208:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META202:![0-9]+]], metadata !DIExpression()), !dbg [[DBG208]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG209:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG209:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG209]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG209]] ; LZCNT: end: @@ -929,10 +929,10 @@ define i32 @p13(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG219]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG219]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG219]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG219]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG219]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG219]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG219]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG219]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG219]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG219]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG219]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG219]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG219]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG220:![0-9]+]] @@ -946,7 +946,7 @@ define i32 @p13(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META216:![0-9]+]], metadata !DIExpression()), !dbg [[DBG222]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG223:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META217:![0-9]+]], metadata !DIExpression()), !dbg [[DBG223]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG224:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG224:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG224]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG224]] ; LZCNT: end: @@ -992,10 +992,10 @@ define i32 @p14(i32 %x) { ; LZCNT-LABEL: @p14( ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true), !dbg [[DBG231:![0-9]+]] -; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG231]] -; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG231]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG231]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG231]] +; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG231]] +; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add nsw i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG231]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG231]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG231]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG231]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG231]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG232:![0-9]+]] @@ -1007,7 +1007,7 @@ define i32 @p14(i32 %x) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META229:![0-9]+]], metadata !DIExpression()), !dbg [[DBG233]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG234:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META230:![0-9]+]], metadata !DIExpression()), !dbg [[DBG234]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG235:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG235:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG235]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG235]] ; LZCNT: end: @@ -1551,10 +1551,10 @@ define i32 @n29(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG449]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG449]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG449]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG449]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG449]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG449]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG449]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG449]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG449]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG449]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG449]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG449]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG449]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG450:![0-9]+]] @@ -1569,7 +1569,7 @@ define i32 @n29(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META446:![0-9]+]], metadata !DIExpression()), !dbg [[DBG453]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG454:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META447:![0-9]+]], metadata !DIExpression()), !dbg [[DBG454]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG455:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG455:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG455]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG455]] ; LZCNT: end: @@ -1616,10 +1616,10 @@ define i32 @n30(i32 %x) { ; LZCNT-LABEL: @n30( ; LZCNT-NEXT: entry: ; LZCNT-NEXT: [[X_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true), !dbg [[DBG462:![0-9]+]] -; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG462]] -; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG462]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG462]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG462]] +; LZCNT-NEXT: [[X_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_NUMLEADINGZEROS]], !dbg [[DBG462]] +; LZCNT-NEXT: [[X_LEADINGONEPOS:%.*]] = add nsw i32 [[X_NUMACTIVEBITS]], -1, !dbg [[DBG462]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 31, [[X_LEADINGONEPOS]], !dbg [[DBG462]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG462]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG462]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG462]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG463:![0-9]+]] @@ -1632,7 +1632,7 @@ define i32 @n30(i32 %x) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META460:![0-9]+]], metadata !DIExpression()), !dbg [[DBG465]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG466:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META461:![0-9]+]], metadata !DIExpression()), !dbg [[DBG466]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG467:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG467:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG467]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG467]] ; LZCNT: end: @@ -1679,10 +1679,10 @@ define i32 @n31(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG477]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG477]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG477]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG477]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG477]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG477]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG477]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG477]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG477]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG477]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG477]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG477]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG477]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG478:![0-9]+]] @@ -1696,7 +1696,7 @@ define i32 @n31(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META474:![0-9]+]], metadata !DIExpression()), !dbg [[DBG480]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG481:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META475:![0-9]+]], metadata !DIExpression()), !dbg [[DBG481]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG482:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG482:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG482]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG482]] ; LZCNT: end: @@ -1750,10 +1750,10 @@ define i32 @n32(i32 %x, i32 %bit) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i32 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG493]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i32 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG493]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X_MASKED]], i1 true), !dbg [[DBG493]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG493]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG493]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG493]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG493]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i32 32, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG493]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i32 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG493]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i32 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG493]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i32 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG493]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i32 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG493]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i32 [[X_CURR]], 1, !dbg [[DBG493]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG494:![0-9]+]] @@ -1767,7 +1767,7 @@ define i32 @n32(i32 %x, i32 %bit) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META490:![0-9]+]], metadata !DIExpression()), !dbg [[DBG496]] ; LZCNT-NEXT: [[TMP1]] = shl i32 [[TMP0]], 1, !dbg [[DBG497:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i32 [[TMP1]], metadata [[META491:![0-9]+]], metadata !DIExpression()), !dbg [[DBG497]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i32 [[LOOP_IV]], 1, !dbg [[DBG498:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i32 [[LOOP_IV]], 1, !dbg [[DBG498:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i32 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG498]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG498]] ; LZCNT: end: @@ -1904,10 +1904,10 @@ define void @t35_i1(i1 %x, i1 %bit, i1* %p0, i1* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i1 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG540]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i1 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG540]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i1 @llvm.ctlz.i1(i1 [[X_MASKED]], i1 true), !dbg [[DBG540]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i1 true, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG540]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i1 true, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG540]] ; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i1 [[X_MASKED_NUMACTIVEBITS]], true, !dbg [[DBG540]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i1 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG540]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i1 [[LOOP_BACKEDGETAKENCOUNT]], true, !dbg [[DBG540]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i1 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG540]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i1 [[LOOP_BACKEDGETAKENCOUNT]], true, !dbg [[DBG540]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i1 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG540]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i1 [[X_CURR]], true, !dbg [[DBG540]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG541:![0-9]+]] @@ -1921,7 +1921,7 @@ define void @t35_i1(i1 %x, i1 %bit, i1* %p0, i1* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META537:![0-9]+]], metadata !DIExpression()), !dbg [[DBG543]] ; LZCNT-NEXT: [[TMP1]] = shl i1 [[TMP0]], true, !dbg [[DBG544:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[TMP1]], metadata [[META538:![0-9]+]], metadata !DIExpression()), !dbg [[DBG544]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i1 [[LOOP_IV]], true, !dbg [[DBG545:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i1 [[LOOP_IV]], true, !dbg [[DBG545:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i1 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG545]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG545]] ; LZCNT: end: @@ -1978,9 +1978,9 @@ define void @t36_i2(i2 %x, i2 %bit, i2* %p0, i2* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i2 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG557]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i2 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG557]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i2 @llvm.ctlz.i2(i2 [[X_MASKED]], i1 true), !dbg [[DBG557]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i2 -2, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG557]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw i2 -2, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG557]] ; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i2 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG557]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i2 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG557]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i2 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG557]] ; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i2 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG557]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i2 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG557]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i2 [[X_CURR]], 1, !dbg [[DBG557]] @@ -2052,10 +2052,10 @@ define void @t37_i3(i3 %x, i3 %bit, i3* %p0, i3* %p1) { ; LZCNT-NEXT: [[BIT_MASK:%.*]] = or i3 [[BIT_LOWBITMASK]], [[BITMASK]], !dbg [[DBG574]] ; LZCNT-NEXT: [[X_MASKED:%.*]] = and i3 [[X:%.*]], [[BIT_MASK]], !dbg [[DBG574]] ; LZCNT-NEXT: [[X_MASKED_NUMLEADINGZEROS:%.*]] = call i3 @llvm.ctlz.i3(i3 [[X_MASKED]], i1 true), !dbg [[DBG574]] -; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub i3 3, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG574]] -; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add i3 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG574]] -; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub i3 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG574]] -; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw i3 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG574]] +; LZCNT-NEXT: [[X_MASKED_NUMACTIVEBITS:%.*]] = sub nuw nsw i3 3, [[X_MASKED_NUMLEADINGZEROS]], !dbg [[DBG574]] +; LZCNT-NEXT: [[X_MASKED_LEADINGONEPOS:%.*]] = add nsw i3 [[X_MASKED_NUMACTIVEBITS]], -1, !dbg [[DBG574]] +; LZCNT-NEXT: [[LOOP_BACKEDGETAKENCOUNT:%.*]] = sub nuw nsw i3 [[BIT]], [[X_MASKED_LEADINGONEPOS]], !dbg [[DBG574]] +; LZCNT-NEXT: [[LOOP_TRIPCOUNT:%.*]] = add nuw nsw i3 [[LOOP_BACKEDGETAKENCOUNT]], 1, !dbg [[DBG574]] ; LZCNT-NEXT: [[X_CURR:%.*]] = shl i3 [[X]], [[LOOP_BACKEDGETAKENCOUNT]], !dbg [[DBG574]] ; LZCNT-NEXT: [[X_NEXT:%.*]] = shl i3 [[X_CURR]], 1, !dbg [[DBG574]] ; LZCNT-NEXT: br label [[LOOP:%.*]], !dbg [[DBG575:![0-9]+]] @@ -2069,7 +2069,7 @@ define void @t37_i3(i3 %x, i3 %bit, i3* %p0, i3* %p1) { ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i1 [[X_CURR_ISBITUNSET]], metadata [[META571:![0-9]+]], metadata !DIExpression()), !dbg [[DBG577]] ; LZCNT-NEXT: [[TMP1]] = shl i3 [[TMP0]], 1, !dbg [[DBG578:![0-9]+]] ; LZCNT-NEXT: call void @llvm.dbg.value(metadata i3 [[TMP1]], metadata [[META572:![0-9]+]], metadata !DIExpression()), !dbg [[DBG578]] -; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw i3 [[LOOP_IV]], 1, !dbg [[DBG579:![0-9]+]] +; LZCNT-NEXT: [[LOOP_IV_NEXT]] = add nuw nsw i3 [[LOOP_IV]], 1, !dbg [[DBG579:![0-9]+]] ; LZCNT-NEXT: [[LOOP_IVCHECK:%.*]] = icmp eq i3 [[LOOP_IV_NEXT]], [[LOOP_TRIPCOUNT]], !dbg [[DBG579]] ; LZCNT-NEXT: br i1 [[LOOP_IVCHECK]], label [[END:%.*]], label [[LOOP]], !dbg [[DBG579]] ; LZCNT: end: |