[llvm] 75d33a3 - [InstCombine] FoldShiftByConstant - consistently use ConstantExpr in logicalshift(trunc(shift(x,c1)),c2) fold. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 06:49:28 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-06T14:48:34+01:00
New Revision: 75d33a3a97c6f6e65ef5139a4a12508716842601
URL: https://github.com/llvm/llvm-project/commit/75d33a3a97c6f6e65ef5139a4a12508716842601
DIFF: https://github.com/llvm/llvm-project/commit/75d33a3a97c6f6e65ef5139a4a12508716842601.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 6e12f8011a36..8ddffe34bdb8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -705,24 +705,16 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *Op1,
// other xforms later if dead.
unsigned SrcSize = SrcTy->getScalarSizeInBits();
unsigned DstSize = TI->getType()->getScalarSizeInBits();
- APInt MaskV(APInt::getLowBitsSet(SrcSize, DstSize));
+ Constant *MaskV =
+ ConstantInt::get(SrcTy, APInt::getLowBitsSet(SrcSize, DstSize));
// The mask we constructed says what the trunc would do if occurring
// between the shifts. We want to know the effect *after* the second
// shift. We know that it is a logical shift by a constant, so adjust the
// mask as appropriate.
- if (I.getOpcode() == Instruction::Shl)
- MaskV <<= Op1C->getZExtValue();
- else {
- assert(I.getOpcode() == Instruction::LShr && "Unknown logical shift");
- MaskV.lshrInPlace(Op1C->getZExtValue());
- }
-
+ MaskV = ConstantExpr::get(I.getOpcode(), MaskV, ShAmt);
// shift1 & 0x00FF
- Value *And = Builder.CreateAnd(NSh,
- ConstantInt::get(I.getContext(), MaskV),
- TI->getName());
-
+ Value *And = Builder.CreateAnd(NSh, MaskV, TI->getName());
// Return the value truncated to the interesting size.
return new TruncInst(And, I.getType());
}
More information about the llvm-commits
mailing list