forked from OSchip/llvm-project
[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:
parent
55aa4e92f7
commit
1cd6b44f26
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue