[llvm-dev] Path condition propagation

Carlos Liam via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 30 19:00:48 PDT 2016


My apologies, you're right; I was comparing against an older version of Clang that didn't do this.

 - CL

> On Jun 30, 2016, at 9:45 PM, Daniel Berlin <dberlin at dberlin.org> wrote:
> 
> 
> 
> On Thu, Jun 30, 2016 at 6:09 PM, Carlos Liam via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> Hi all,
> 
> Consider this C code:
> 
> #include <stdbool.h>
> 
> bool func(int n1, int n2, bool b) {
>     bool greater = n1 > n2;
>     if (greater && b) {
>         if (n1 == n2) {
>             return false; // unreachable
>         }
>     }
>     return true;
> }
> 
> The line marked unreachable cannot be reached, however currently LLVM does not optimize it out
> ?????
> Yes it does.
> [dannyb at dannyb-macbookpro3 18:39:18] ~/sources/llvm (git-svn)-[newgvn-predicates]- :( $ clang -c -emit-llvm ~/greater.c -O1
> [dannyb at dannyb-macbookpro3 18:39:22] ~/sources/llvm (git-svn)-[newgvn-predicates]- :) $ debug-build/bin/llvm-dis greater.bc
> [dannyb at dannyb-macbookpro3 18:39:24] ~/sources/llvm (git-svn)-[newgvn-predicates]- :) $ cat greater.ll
> ; Function Attrs: norecurse nounwind readnone ssp uwtable
> define zeroext i1 @func(i32, i32, i1 zeroext) #0 {
>   ret i1 true
> } 
> 
> 
> opt -simplifycfg -instcombine does the same thing to it if you use -O0 with clang 
>  
> I believe this is because LLVM does not recognize that meeting path conditions like, for example, X && Y logically means that X is true and Y is true.
> 
> 
> Yes it does. See both GVN's propagateequality and correlatedvaluepropagation, among other things :)
> 
> In this case, simplifycfg +instcombine will do it
> 
> The new predicate support i'm building for GVN will also do it.
>  
> 
> I'm interested in creating a patch to remedy this; is there a file or function I should look at?
> 
> Thanks in advance.
> 
>  - CL
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160630/e6e554ca/attachment.html>


More information about the llvm-dev mailing list