[PATCH] D82005: [InstCombine] Replace selects with Phis

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 08:03:49 PDT 2020


spatel added a comment.

I'm not sure what direction we want to take this, but forming phis out of selects may conflict with SimplifyCFG. It can create select from phi in cases like this:

  declare void @call(i32)
  
  define i32 @select_or_phi(i1 %cond, i32 %x, i32 %y) {
  entry:
    br i1 %cond, label %if.true, label %if.false
  
  if.true:
    call void @call(i32 %x)
    br label %merge
  
  if.false:
    call void @call(i32 %y)
    br label %merge
  
  merge:
    %r1 = phi i32 [ %y, %if.false ], [ %x, %if.true ]
    %r2 = select i1 %cond, i32 %x, i32 %y
    %r = add i32 %r1, %r2
    ret i32 %r
  }



  $ opt -O1 phi.ll -S
  
  declare void @call(i32)
  
  define i32 @select_or_phi(i1 %cond, i32 %x, i32 %y) {
  entry:
    %y.sink = select i1 %cond, i32 %x, i32 %y
    %r1 = select i1 %cond, i32 %x, i32 %y
    call void @call(i32 %y.sink)
    %r2 = select i1 %cond, i32 %x, i32 %y
    %r = add i32 %r1, %r2
    ret i32 %r
  }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82005/new/

https://reviews.llvm.org/D82005





More information about the llvm-commits mailing list