[PATCH] D78765: [TRE] Fix bug in handling of switch statements

Layton Kifer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 07:30:35 PDT 2020


laytonio added a comment.

I'm trying this approach now, but I'm having a hard time seeing a good way to transform this case:

  define i32 @func(i32 %index) local_unnamed_addr {
  entry:
    %0 = icmp eq i32 %index, 0
    br i1 %0, label %then, label %else
  
  then:
    ret i32 12
  
  else:
    %1 = call i32 @func(i32 0)
    ret i32 3
  }

Current transform:

  define i32 @func(i32 %index) local_unnamed_addr {
  entry:
    br label %tailrecurse
  
  tailrecurse:                                      ; preds = %else, %entry
    %accumulator.tr = phi i32 [ 12, %entry ], [ 3, %else ]
    %index.tr = phi i32 [ %index, %entry ], [ 0, %else ]
    %0 = icmp eq i32 %index.tr, 0
    br i1 %0, label %then, label %else
  
  then:                                             ; preds = %tailrecurse
    ret i32 %accumulator.tr
  
  else:                                             ; preds = %tailrecurse
    br label %tailrecurse
  }

We could do something like this:

  define i32 @func(i32 %index) local_unnamed_addr {
  entry:
    br label %tailrecurse
  
  tailrecurse:                                      ; preds = %else, %entry
    %selector.tr = phi i1 [ true, %entry ], [ false, %else ]
    %accumulator.tr = phi i32 [ 0, %entry ], [ %selection.tr1, %else ]
    %index.tr = phi i32 [ %index, %entry ], [ 0, %else ]
    %0 = icmp eq i32 %index.tr, 0
    br i1 %0, label %then, label %else
  
  then:                                             ; preds = %tailrecurse
    %selection.tr = select i1 %selector.tr, i32 12, i32 %accumulator.tr
    ret i32 %selection.tr
  
  else:                                             ; preds = %tailrecurse
    %selection.tr1 = select i1 %selector.tr, i32 3, i32 %accumulator.tr
    br label %tailrecurse
  }

But that really doesn't seem all that clean to me. Is there a better way to do this that I am missing?


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

https://reviews.llvm.org/D78765





More information about the llvm-commits mailing list