From 2f9c6dafe32c2a172630aff9ee7f2dde8528b9b3 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 24 May 2017 18:40:25 +0000 Subject: [InstCombine] Merge together the SimplifyDemandedUseBits implementations for ZExt and Trunc. NFC While there avoid resizing the DemandedMask twice. Make a copy into a separate variable instead. This potentially removes an allocation on large bit widths. With the use of the zextOrTrunc methods on APInt and KnownBits these can be made almost source identical. The only difference is the zero of the upper bits for ZExt. This is similar to how its done in computeKnownBits in ValueTracking. llvm-svn: 303791 --- .../InstCombine/InstCombineSimplifyDemanded.cpp | 31 +++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 9b58fae5e4c..5df55f01b83 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -325,14 +325,18 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Known.One = RHSKnown.One & LHSKnown.One; Known.Zero = RHSKnown.Zero & LHSKnown.Zero; break; + case Instruction::ZExt: case Instruction::Trunc: { - unsigned truncBf = I->getOperand(0)->getType()->getScalarSizeInBits(); - DemandedMask = DemandedMask.zext(truncBf); - Known = Known.zext(truncBf); - if (SimplifyDemandedBits(I, 0, DemandedMask, Known, Depth + 1)) + unsigned SrcBitWidth = I->getOperand(0)->getType()->getScalarSizeInBits(); + + APInt InputDemandedMask = DemandedMask.zextOrTrunc(SrcBitWidth); + KnownBits InputKnown(SrcBitWidth); + if (SimplifyDemandedBits(I, 0, InputDemandedMask, InputKnown, Depth + 1)) return I; - DemandedMask = DemandedMask.trunc(BitWidth); - Known = Known.trunc(BitWidth); + Known = Known.zextOrTrunc(BitWidth); + // Any top bits are known to be zero. + if (BitWidth > SrcBitWidth) + Known.Zero.setBitsFrom(SrcBitWidth); assert(!Known.hasConflict() && "Bits known to be one AND zero?"); break; } @@ -357,21 +361,6 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, return I; assert(!Known.hasConflict() && "Bits known to be one AND zero?"); break; - case Instruction::ZExt: { - // Compute the bits in the result that are not present in the input. - unsigned SrcBitWidth =I->getOperand(0)->getType()->getScalarSizeInBits(); - - DemandedMask = DemandedMask.trunc(SrcBitWidth); - Known = Known.trunc(SrcBitWidth); - if (SimplifyDemandedBits(I, 0, DemandedMask, Known, Depth + 1)) - return I; - DemandedMask = DemandedMask.zext(BitWidth); - Known = Known.zext(BitWidth); - assert(!Known.hasConflict() && "Bits known to be one AND zero?"); - // The top bits are known to be zero. - Known.Zero.setBitsFrom(SrcBitWidth); - break; - } case Instruction::SExt: { // Compute the bits in the result that are not present in the input. unsigned SrcBitWidth = I->getOperand(0)->getType()->getScalarSizeInBits(); -- cgit v1.2.3