Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -3488,6 +3488,62 @@ return ::SimplifyFCmpInst(Predicate, LHS, RHS, FMF, Q, RecursionLimit); } +static bool +IsOverflowingBinaryOperatorSafe(const OverflowingBinaryOperator *OBO, + const SimplifyQuery &Q) { + bool NUW = OBO->hasNoUnsignedWrap(), NSW = OBO->hasNoSignedWrap(); + if (!NUW && !NSW) + return true; + const Instruction *I = dyn_cast(OBO); + if (!I) + return false; + Value *LHS = OBO->getOperand(0), *RHS = OBO->getOperand(1); + switch (OBO->getOpcode()) { + default: + return false; + case Instruction::Shl: + const APInt *ShAmtAPInt; + if (!match(RHS, m_APInt(ShAmtAPInt))) + return false; + + unsigned ShAmt = ShAmtAPInt->getZExtValue(); + unsigned BitWidth = OBO->getType()->getScalarSizeInBits(); + + if (NUW && !MaskedValueIsZero(LHS, APInt::getHighBitsSet(BitWidth, ShAmt), + Q.DL, 0, Q.AC, I, Q.DT)) + return false; + if (NSW && ComputeNumSignBits(LHS, Q.DL, 0, Q.AC, I, Q.DT) <= ShAmt) + return false; + return true; + } +} + +static bool IsPossiblyExactOperatorSafe(const PossiblyExactOperator *PEO, + const SimplifyQuery &Q) { + if (!PEO->isExact()) + return true; + const Instruction *I = dyn_cast(PEO); + if (!I) + return false; + switch (PEO->getOpcode()) { + default: + return false; + case Instruction::LShr: + case Instruction::AShr: + Value *Op0 = I->getOperand(0), *Op1 = I->getOperand(1); + + const APInt *ShAmtAPInt; + if (!match(Op1, m_APInt(ShAmtAPInt))) + return false; + + unsigned ShAmt = ShAmtAPInt->getZExtValue(); + unsigned BitWidth = I->getType()->getScalarSizeInBits(); + + return MaskedValueIsZero(Op0, APInt::getLowBitsSet(BitWidth, ShAmt), Q.DL, + 0, Q.AC, I, Q.DT); + } +} + /// See if V simplifies when its operand Op is replaced with RepOp. static const Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, @@ -3512,11 +3568,11 @@ // %sel = select i1 %cmp, i32 -2147483648, i32 %add // // We can't replace %sel with %add unless we strip away the flags. - if (isa(B)) - if (B->hasNoSignedWrap() || B->hasNoUnsignedWrap()) + if (OverflowingBinaryOperator *OBO = dyn_cast(B)) + if (!IsOverflowingBinaryOperatorSafe(OBO, Q)) return nullptr; - if (isa(B)) - if (B->isExact()) + if (PossiblyExactOperator *PEO = dyn_cast(B)) + if (!IsPossiblyExactOperatorSafe(PEO, Q)) return nullptr; if (MaxRecurse) { Index: test/Transforms/InstCombine/select-bitext-bitwise-ops.ll =================================================================== --- test/Transforms/InstCombine/select-bitext-bitwise-ops.ll +++ test/Transforms/InstCombine/select-bitext-bitwise-ops.ll @@ -3,13 +3,11 @@ define i64 @sel_false_val_is_a_masked_shl_of_true_val1(i32 %x, i64 %y) { ; CHECK-LABEL: @sel_false_val_is_a_masked_shl_of_true_val1( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 %y, [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 15 %2 = shl nuw nsw i32 %1, 2 @@ -39,13 +37,11 @@ define i64 @sel_false_val_is_a_masked_lshr_of_true_val1(i32 %x, i64 %y) { ; CHECK-LABEL: @sel_false_val_is_a_masked_lshr_of_true_val1( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 60 -; CHECK-NEXT: [[TMP2:%.*]] = lshr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 %x, 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 %y, [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 60 %2 = lshr i32 %1, 2 @@ -75,13 +71,11 @@ define i64 @sel_false_val_is_a_masked_ashr_of_true_val1(i32 %x, i64 %y) { ; CHECK-LABEL: @sel_false_val_is_a_masked_ashr_of_true_val1( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2147483588 -; CHECK-NEXT: [[TMP2:%.*]] = ashr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 %x, 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 %y, [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, -2147483588 %2 = ashr i32 %1, 2 Index: test/Transforms/InstCombine/select-obo-peo-ops.ll =================================================================== --- test/Transforms/InstCombine/select-obo-peo-ops.ll +++ test/Transforms/InstCombine/select-obo-peo-ops.ll @@ -3,13 +3,11 @@ define i64 @test_shl_nuw_nsw__all_are_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl_nuw_nsw__all_are_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 15 %2 = shl nuw nsw i32 %1, 2 @@ -22,13 +20,11 @@ define i64 @test_shl_nuw__all_are_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl_nuw__all_are_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 15 %2 = shl nuw i32 %1, 2 @@ -41,13 +37,11 @@ define i64 @test_shl_nsw__all_are_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl_nsw__all_are_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 15 %2 = shl nsw i32 %1, 2 @@ -60,13 +54,11 @@ define i64 @test_shl__all_are_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl__all_are_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 15 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 60 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 15 %2 = shl i32 %1, 2 @@ -98,13 +90,11 @@ define i64 @test_shl_nuw__nuw_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl_nuw__nuw_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 1073741822 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -8 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 1073741822 %2 = shl nuw i32 %1, 2 @@ -136,13 +126,11 @@ define i64 @test_shl__nuw_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_shl__nuw_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 1073741822 -; CHECK-NEXT: [[TMP2:%.*]] = shl nuw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -8 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 1073741822 %2 = shl i32 %1, 2 @@ -194,12 +182,10 @@ define i32 @test_shl_nsw__nsw_is_safe(i32 %x) { ; CHECK-LABEL: @test_shl_nsw__nsw_is_safe( ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -83886080 -; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], -83886079 -; CHECK-NEXT: [[TMP3:%.*]] = shl nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], i32 -335544316, i32 [[TMP3]] -; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[TMP4]], [[TMP1]] -; CHECK-NEXT: [[TMP6:%.*]] = mul i32 [[TMP5]], [[TMP3]] -; CHECK-NEXT: ret i32 [[TMP6]] +; CHECK-NEXT: [[TMP2:%.*]] = shl nsw i32 [[TMP1]], 2 +; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP1]] +; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], [[TMP2]] +; CHECK-NEXT: ret i32 [[TMP4]] ; %1 = or i32 %x, -83886080 %2 = icmp eq i32 %1, -83886079 @@ -213,12 +199,10 @@ define i32 @test_shl__nsw_is_safe(i32 %x) { ; CHECK-LABEL: @test_shl__nsw_is_safe( ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -83886080 -; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], -83886079 -; CHECK-NEXT: [[TMP3:%.*]] = shl nsw i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], i32 -335544316, i32 [[TMP3]] -; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[TMP4]], [[TMP1]] -; CHECK-NEXT: [[TMP6:%.*]] = mul i32 [[TMP5]], [[TMP3]] -; CHECK-NEXT: ret i32 [[TMP6]] +; CHECK-NEXT: [[TMP2:%.*]] = shl nsw i32 [[TMP1]], 2 +; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP1]] +; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], [[TMP2]] +; CHECK-NEXT: ret i32 [[TMP4]] ; %1 = or i32 %x, -83886080 %2 = icmp eq i32 %1, -83886079 @@ -306,13 +290,11 @@ define i64 @test_lshr_exact__exact_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_lshr_exact__exact_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 60 -; CHECK-NEXT: [[TMP2:%.*]] = lshr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 60 %2 = lshr exact i32 %1, 2 @@ -325,13 +307,11 @@ define i64 @test_lshr__exact_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_lshr__exact_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 60 -; CHECK-NEXT: [[TMP2:%.*]] = lshr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 15 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, 60 %2 = lshr i32 %1, 2 @@ -380,13 +360,11 @@ define i64 @test_ashr_exact__exact_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_ashr_exact__exact_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2147483588 -; CHECK-NEXT: [[TMP2:%.*]] = ashr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, -2147483588 %2 = ashr exact i32 %1, 2 @@ -399,13 +377,11 @@ define i64 @test_ashr__exact_is_safe(i32 %x, i64 %y) { ; CHECK-LABEL: @test_ashr__exact_is_safe( -; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2147483588 -; CHECK-NEXT: [[TMP2:%.*]] = ashr exact i32 [[TMP1]], 2 -; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP1]], 0 -; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[TMP3]], i32 0, i32 [[TMP2]] -; CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[NARROW]] to i64 -; CHECK-NEXT: [[TMP5:%.*]] = ashr i64 [[Y:%.*]], [[TMP4]] -; CHECK-NEXT: ret i64 [[TMP5]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 2 +; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -536870897 +; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 +; CHECK-NEXT: [[TMP4:%.*]] = ashr i64 [[Y:%.*]], [[TMP3]] +; CHECK-NEXT: ret i64 [[TMP4]] ; %1 = and i32 %x, -2147483588 %2 = ashr i32 %1, 2