[PATCH] D93015: Fold comparison of __builtin_object_size expression with -1 for non-const size

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 02:27:40 PST 2020


serge-sans-paille added inline comments.


================
Comment at: llvm/lib/Analysis/MemoryBuiltins.cpp:538
+    // Find the constant part of the conditional branch.  If there is none,
+    // we bail out.
+    if (isa<Constant>(Op0))
----------------
It's probably better to walk through the `I->uses()`, filter out on `getUser()` and access the operand straight with `getOperandNo()`


================
Comment at: llvm/lib/Analysis/MemoryBuiltins.cpp:549
+      continue;
+
+    ICmpInst::Predicate Pred = CI->getUnsignedPredicate();
----------------
This looks very similar to generating a call to `llvm.assume`, right?

You could generate a call to

```
  %cmpnot = icmp ne i64 %objsize, -1
  call void @llvm.assume(i1 %cmpnot)
```

And let the magic happen ;-)


================
Comment at: llvm/lib/Analysis/MemoryBuiltins.cpp:610
+          !isa<Constant>(SizeOffsetPair.second))
+        foldNonConstantCompares(ObjectSize);
+
----------------
ok, now I get it, you're folding only if you know for sure that the computation can be done. Generating an assume may help keeping the code easy to read here.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93015/new/

https://reviews.llvm.org/D93015



More information about the llvm-commits mailing list