[llvm-commits] [llvm] r121671 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/switch_create.ll

Chris Lattner sabre at nondot.org
Tue Dec 14 22:10:51 PST 2010


On Dec 13, 2010, at 4:29 AM, Frits van Bommel wrote:
> I have some code where this doesn't work, probably due to the
> requirement for the only use of the icmp to be a phi. A reduced test
> case:
> =====
> bool foo(int x) { return x == 1; }
> bool bar(int x) { return x == 2; }
> bool baz(int x) { return x == 3; }
> 
> bool quux(int x) {
>  return foo(x) || bar(x) || baz(x);
> }
> =====
> The problem seems to be that the return gets duplicated into the two
> branches before inlining, causing quux() to come out of clang -O3 like
> this:
> =====
> define zeroext i1 @quux(int)(i32 %x) nounwind readnone {
> entry:
>  switch i32 %x, label %lor.rhs [
>    i32 1, label %lor.end
>    i32 2, label %lor.end
>  ]
> 
> lor.rhs:                                          ; preds = %entry
>  %cmp.i5 = icmp eq i32 %x, 3                     ; [#uses=1]
>  ret i1 %cmp.i5
> 
> lor.end:                                          ; preds = %entry, %entry
>  ret i1 true
> }
> =====

Yes, this is another irritating example of PR8575, which is due to us duplicating ret's instead of forcing there to be at most one.

-Chris



More information about the llvm-commits mailing list