[InstCombine] add one-use check to shift-shift transform

We don't want to create extra instructions, and this
could infinite loop with the proposed transform in D110170.
This commit is contained in:
Sanjay Patel 2021-09-22 16:16:49 -04:00
parent 55aa4e92f7
commit 1cd6b44f26
2 changed files with 3 additions and 4 deletions

View File

@ -702,7 +702,7 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
Instruction *TrOp;
const APInt *TrShiftAmt;
if (I.isLogicalShift() && match(Op0, m_Trunc(m_Instruction(TrOp))) &&
match(TrOp, m_Shift(m_Value(), m_APInt(TrShiftAmt))) &&
match(TrOp, m_OneUse(m_Shift(m_Value(), m_APInt(TrShiftAmt)))) &&
TrShiftAmt->ult(TrOp->getType()->getScalarSizeInBits())) {
Type *SrcTy = TrOp->getType();

View File

@ -266,9 +266,8 @@ define i16 @extra_use_on_first_shift(i32 %x) {
; CHECK-LABEL: @extra_use_on_first_shift(
; CHECK-NEXT: [[A:%.*]] = ashr i32 [[X:%.*]], 3
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[SH1:%.*]] = lshr i32 [[A]], 6
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[SH1]] to i16
; CHECK-NEXT: [[SH:%.*]] = and i16 [[TMP1]], 1023
; CHECK-NEXT: [[TR:%.*]] = trunc i32 [[A]] to i16
; CHECK-NEXT: [[SH:%.*]] = lshr i16 [[TR]], 6
; CHECK-NEXT: ret i16 [[SH]]
;
%a = ashr i32 %x, 3