[llvm] [ValueTracking] Handle assume( trunc x to i1) (PR #118406)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 14:15:29 PST 2024


================
@@ -844,17 +847,14 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
 
     Value *Arg = I->getArgOperand(0);
 
-    if (Arg == V && isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
-      assert(BitWidth == 1 && "assume operand is not i1?");
-      (void)BitWidth;
-      Known.setAllOnes();
+    if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
+        isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
+      Known.One.setBit(0);
       return;
     }
-    if (match(Arg, m_Not(m_Specific(V))) &&
+    if (match(Arg, m_Not(m_TruncOrSelf(m_Specific(V)))) &&
----------------
andjo403 wrote:

this is the pattern that caused the "ephemeral value" issue. one example of the issue is:
```
define i1 @assumeNot(i8 %x) {
  %trunc = trunc i8 %x to i1
  %xor = xor i1 %trunc, true
  call void @llvm.assume(i1 %xor)
  ret i1 %trunc
}
```
where the `%trunc` is not ephemeral as not all uses is ephemeral.

feels like it shall be ephemeral as the `%xor = xor i1 %trunc, true` only has one used and that is as argument to the assume.

if `%trunc` had been the argument to the assume this code hade made it ephemeral 
https://github.com/llvm/llvm-project/blob/ce7771902dc50d900de639d499a60486b83f70e0/llvm/lib/Analysis/ValueTracking.cpp#L457-L461

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


More information about the llvm-commits mailing list