Index: lib/Transforms/InstCombine/InstCombineShifts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineShifts.cpp +++ lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -559,8 +559,8 @@ return new ZExtInst(Builder.CreateShl(X, ShAmt), Ty); } - // (X >>u C) << C --> X & (-1 << C) - if (match(Op0, m_LShr(m_Value(X), m_Specific(Op1)))) { + // (X >> C) << C --> X & (-1 << C) + if (match(Op0, m_Shr(m_Value(X), m_Specific(Op1)))) { APInt Mask(APInt::getHighBitsSet(BitWidth, BitWidth - ShAmt)); return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, Mask)); } Index: test/Transforms/InstCombine/shift.ll =================================================================== --- test/Transforms/InstCombine/shift.ll +++ test/Transforms/InstCombine/shift.ll @@ -221,6 +221,19 @@ ret i32 %C } +;; ((A | 0xC0000000) >> 8) << 8 === (A & 3FFFFF00) | 0xC0000000 +define i32 @test12a(i32 %A) { +; CHECK-LABEL: @test12a( +; CHECK-NEXT: [[a:%.*]] = and i32 %A, 1073741568 +; CHECK-NEXT: [[C:%.*]] = or i32 [[a]], -1073741824 +; CHECK-NEXT: ret i32 [[C]] +; + %a = or i32 %A, -1073741824 + %B = ashr i32 %a, 8 + %C = shl i32 %B, 8 + ret i32 %C +} + ;; This transformation is deferred to DAGCombine: ;; (A >> 3) << 4 === (A & -8) * 2 ;; The shl may be valuable to scalar evolution.