[llvm] [LVI] Add trunc to i1 handling. (PR #124480)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 1 14:57:29 PST 2025


================
@@ -1283,6 +1285,28 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
   return ValueLatticeElement::getOverdefined();
 }
 
+ValueLatticeElement LazyValueInfoImpl::getValueFromTrunc(Value *Val,
+                                                         TruncInst *Trunc,
+                                                         bool IsTrueDest) {
+  assert(Trunc->getType()->isIntOrIntVectorTy(1));
+
+  if (Trunc->getOperand(0) != Val)
+    return ValueLatticeElement::getOverdefined();
+
+  Type *Ty = Val->getType();
+
+  if (Trunc->hasNoUnsignedWrap()) {
+    if (IsTrueDest)
+      return ValueLatticeElement::get(
+          Constant::getIntegerValue(Ty, APInt(Ty->getScalarSizeInBits(), 1)));
+    return ValueLatticeElement::get(Constant::getNullValue(Ty));
----------------
nikic wrote:

You're right, I got confused with the types here. And yes, using ConstantInt::get is preferable. (getIntegerValue is a specialized API if you need to potentially create an inttoptr expression...)

https://github.com/llvm/llvm-project/pull/124480


More information about the llvm-commits mailing list