[PATCH] D11819: [RewriteStatepointsForGC] Avoid using unrelocated pointers after safepoints

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 15:51:11 PDT 2015


sanjoy added inline comments.

================
Comment at: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:2424
@@ +2423,3 @@
+        return dyn_cast<Instruction>(BI->getCondition());
+    if (auto *SI = dyn_cast<SwitchInst>(TI))
+      return dyn_cast<Instruction>(SI->getCondition());
----------------
chenli wrote:
> sanjoy wrote:
> > A `switch` on an `icmp` is equivalent to a `br`; perhaps we should just teach LLVM to transform
> > 
> > 
> > ```
> >   %c = icmp slt i32 %x, 0
> >   switch i1 %c, label %def [ i1 0, label %f
> >                              i1 1, label %t ]
> > ```
> > 
> > to
> > 
> > ```
> >   %c = icmp slt i32 %x, 0
> >   br i1 %c, label %t, label %f
> > ```
> >  
> > so that we don't have to deal with `switch` separately here?
> > 
> > (Right now LLVM does not do the said transform, which surprised me).
> > 
> > 
> > If you remove the `switch` case (pun intended!) here then you should be able to use a simple expression from PatternMatch.h to match a conditional `br` on an `icmp`.
> Hmm, I think -simplifycfg should do the transformation. Do we ever see SwitchInst in practice?
Here's the full example

```
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare void @g()
declare void @h()
declare void @i()

define void @f(i32 %x) {
 entry:
  %c = icmp slt i32 %x, 0
  switch i1 %c, label %def [ i1 0, label %f
                             i1 1, label %t ]

 t:
  call void @g()
  ret void

 f:
  call void @h()
  ret void

 def:
  call void @i()
  ret void
}
```

`opt -O3` does not transform the `switch` to a `br`.


http://reviews.llvm.org/D11819





More information about the llvm-commits mailing list