[PATCH] D93015: Fold comparison of __builtin_object_size expression with -1 for non-const size
Siddhesh Poyarekar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 17 04:28:03 PST 2020
siddhesh marked an inline comment as done.
siddhesh added inline comments.
================
Comment at: llvm/lib/Analysis/MemoryBuiltins.cpp:549
+ continue;
+
+ ICmpInst::Predicate Pred = CI->getUnsignedPredicate();
----------------
serge-sans-paille wrote:
> 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 ;-)
I tried, but left it as is for now. It works fine when it's just `Builder.CreateAssumption(Cond)`, i.e. when the condition is true. However for the false condition, doing `Builder.CreateAssumption(Builder.CreateNot(Cond))` does not work because llvm is unable to work out the relationships and fold the conditions away. I tried ordering the `assume`, `cmp` and the `cmp.not` instructions in different ways, but no dice.
ISTM the other alternative would be to invert the condition and then update the user branch instructions, thus allowing `Builder.CreateAssumption(Cond)` but that doesn't seem too different from `replaceAllusesWith()`. What do you think?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93015/new/
https://reviews.llvm.org/D93015
More information about the llvm-commits
mailing list