[PATCH] Expand SimplifyCFG to convert certain simple switches to selects

Marcello Maggioni hayarms at gmail.com
Sat Jun 21 04:38:59 PDT 2014


Sorry for having added the comments in different moments, but the answers came out at different moments in times :P

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:3725
@@ +3724,3 @@
+                 DL);
+  // No default case makes us assume that default is not possible.
+  DefaultResult =
----------------
Philip Reames wrote:
> It looks like you might end up with PHI unset if you had a switch with only a default case.  Could such a switch reach here?  
I tried to catch a case here where that happens, but I couldn't reproduce this case by trying to compile something like this:

define i32 @foo(i32 %a) #0 {
entry:
  switch i32 %a, label %sw.default [
  ]

sw.default:                                       ; preds = %entry
  ret i32 10
}

with opt -simplifycfg

Anyway, if that is the case the test:

  if (UniqueResults.size() != 2)
    return false;

in SwitchToSelect() should fail, because a PHI must be set if at least one Result is found, which would prevent the assertion on the next line to trigger.

I think bailing out in a case like that would be ok, because I don't think this is the right place where to handle a case like this one.

http://reviews.llvm.org/D4219






More information about the llvm-commits mailing list