Skip to content

Commit 002da67

Browse files
committed
[InstCombine] Require ImmConstant in shift of shift fold
This fixes an infinite loop reported at: 82f68a9#commitcomment-132406739
1 parent a419666 commit 002da67

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *C1,
760760
// (C2 >> X) >> C1 --> (C2 >> C1) >> X
761761
Constant *C2;
762762
Value *X;
763-
if (match(Op0, m_BinOp(I.getOpcode(), m_Constant(C2), m_Value(X))))
763+
if (match(Op0, m_BinOp(I.getOpcode(), m_ImmConstant(C2), m_Value(X))))
764764
return BinaryOperator::Create(
765765
I.getOpcode(), Builder.CreateBinOp(I.getOpcode(), C2, C1), X);
766766

llvm/test/Transforms/InstCombine/shift-shift.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,15 @@ define <2 x i8> @lshr_shl_demand5_nonuniform_vec_both(<2 x i8> %x) {
732732
%r = and <2 x i8> %shl, <i8 -4, i8 -16>
733733
ret <2 x i8> %r
734734
}
735+
736+
@g = external global i8, align 8
737+
738+
define i64 @ashr_ashr_constexpr() {
739+
; CHECK-LABEL: @ashr_ashr_constexpr(
740+
; CHECK-NEXT: [[SHR2:%.*]] = ashr exact i64 ptrtoint (ptr @g to i64), 3
741+
; CHECK-NEXT: ret i64 [[SHR2]]
742+
;
743+
%shr = ashr i64 ptrtoint (ptr @g to i64), 1
744+
%shr2 = ashr i64 %shr, 2
745+
ret i64 %shr2
746+
}

0 commit comments

Comments
 (0)