Commit 002da67d authored by Nikita Popov's avatar Nikita Popov
Browse files

[InstCombine] Require ImmConstant in shift of shift fold

parent a4196666
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -760,7 +760,7 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *C1,
  // (C2 >> X) >> C1 --> (C2 >> C1) >> X
  Constant *C2;
  Value *X;
  if (match(Op0, m_BinOp(I.getOpcode(), m_Constant(C2), m_Value(X))))
  if (match(Op0, m_BinOp(I.getOpcode(), m_ImmConstant(C2), m_Value(X))))
    return BinaryOperator::Create(
        I.getOpcode(), Builder.CreateBinOp(I.getOpcode(), C2, C1), X);

+12 −0
Original line number Diff line number Diff line
@@ -732,3 +732,15 @@ define <2 x i8> @lshr_shl_demand5_nonuniform_vec_both(<2 x i8> %x) {
  %r = and <2 x i8> %shl, <i8 -4, i8 -16>
  ret <2 x i8> %r
}

@g = external global i8, align 8

define i64 @ashr_ashr_constexpr() {
; CHECK-LABEL: @ashr_ashr_constexpr(
; CHECK-NEXT:    [[SHR2:%.*]] = ashr exact i64 ptrtoint (ptr @g to i64), 3
; CHECK-NEXT:    ret i64 [[SHR2]]
;
  %shr = ashr i64 ptrtoint (ptr @g to i64), 1
  %shr2 = ashr i64 %shr, 2
  ret i64 %shr2
}