From 75d33a3a97c6f6e65ef5139a4a12508716842601 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Tue, 6 Oct 2020 13:44:17 +0100 Subject: [PATCH] [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. --- llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 6e12f80..8ddffe3 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()); } -- 2.7.4