Skip to content

Commit 75d33a3

Browse files
committed
[InstCombine] FoldShiftByConstant - consistently use ConstantExpr in logicalshift(trunc(shift(x,c1)),c2) fold. NFCI.
This still only gets used for scalar types but now always uses ConstantExpr in preparation for vector support - it was using APInt methods in some places.
1 parent 8a3cbb1 commit 75d33a3

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -705,24 +705,16 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
705705
// other xforms later if dead.
706706
unsigned SrcSize = SrcTy->getScalarSizeInBits();
707707
unsigned DstSize = TI->getType()->getScalarSizeInBits();
708-
APInt MaskV(APInt::getLowBitsSet(SrcSize, DstSize));
708+
Constant *MaskV =
709+
ConstantInt::get(SrcTy, APInt::getLowBitsSet(SrcSize, DstSize));
709710

710711
// The mask we constructed says what the trunc would do if occurring
711712
// between the shifts. We want to know the effect *after* the second
712713
// shift. We know that it is a logical shift by a constant, so adjust the
713714
// mask as appropriate.
714-
if (I.getOpcode() == Instruction::Shl)
715-
MaskV <<= Op1C->getZExtValue();
716-
else {
717-
assert(I.getOpcode() == Instruction::LShr && "Unknown logical shift");
718-
MaskV.lshrInPlace(Op1C->getZExtValue());
719-
}
720-
715+
MaskV = ConstantExpr::get(I.getOpcode(), MaskV, ShAmt);
721716
// shift1 & 0x00FF
722-
Value *And = Builder.CreateAnd(NSh,
723-
ConstantInt::get(I.getContext(), MaskV),
724-
TI->getName());
725-
717+
Value *And = Builder.CreateAnd(NSh, MaskV, TI->getName());
726718
// Return the value truncated to the interesting size.
727719
return new TruncInst(And, I.getType());
728720
}

0 commit comments

Comments
 (0)