aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2022-12-30 23:12:20 -0700
committerOwen Anderson <resistor@mac.com>2023-01-03 15:26:21 -0700
commitec40c8f6fe8477e22b9a1e5a3140dd3f7b247588 (patch)
treee61ed4345125fe657a92cf333f02394d902cab97 /llvm/lib/Analysis/ValueTracking.cpp
parent6df5464a463b8ada2df167595286aa2b6510dd16 (diff)
downloadllvm-ec40c8f6fe8477e22b9a1e5a3140dd3f7b247588.zip
llvm-ec40c8f6fe8477e22b9a1e5a3140dd3f7b247588.tar.gz
llvm-ec40c8f6fe8477e22b9a1e5a3140dd3f7b247588.tar.bz2
[ValueTracking] Improve ComputeNumSignBits to handle Trunc
Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D140796
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index b563154..d12e4c7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3312,10 +3312,17 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
return Tmp;
}
- case Instruction::Trunc:
- // FIXME: it's tricky to do anything useful for this, but it is an
- // important case for targets like X86.
- break;
+ case Instruction::Trunc: {
+ // If the input contained enough sign bits that some remain after the
+ // truncation, then we can make use of that. Otherwise we don't know
+ // anything.
+ Tmp = ComputeNumSignBits(U->getOperand(0), Depth + 1, Q);
+ unsigned OperandTyBits = U->getOperand(0)->getType()->getScalarSizeInBits();
+ if (Tmp > (OperandTyBits - TyBits))
+ return Tmp - (OperandTyBits - TyBits);
+
+ return 1;
+ }
case Instruction::ExtractElement:
// Look through extract element. At the moment we keep this simple and