Skip to content

Commit

Permalink
[InstCombine] Require ImmConstant in shift of shift fold
Browse files Browse the repository at this point in the history
This fixes an infinite loop reported at:
82f68a9#commitcomment-132406739
  • Loading branch information
nikic committed Nov 13, 2023
1 parent a419666 commit 002da67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions llvm/test/Transforms/InstCombine/shift-shift.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 002da67

Please sign in to comment.