summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-05-24 18:40:25 +0000
committerCraig Topper <craig.topper@gmail.com>2017-05-24 18:40:25 +0000
commit2f9c6dafe32c2a172630aff9ee7f2dde8528b9b3 (patch)
tree2a54f43df1d0031ed10fdd05e1726742c810fe5f /llvm/lib/Transforms
parent1a0128faaa78da448edd8a4f2fe48cd394c1a838 (diff)
downloadbcm5719-llvm-2f9c6dafe32c2a172630aff9ee7f2dde8528b9b3.tar.gz
bcm5719-llvm-2f9c6dafe32c2a172630aff9ee7f2dde8528b9b3.zip
[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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp31
1 files changed, 10 insertions, 21 deletions
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();
OpenPOWER on IntegriCloud