[PATCH] D155395: [SimplifyCFG] Remove identical successors in switch instructions in simple cases.

DianQK via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 16 07:24:29 PDT 2023


DianQK abandoned this revision.
DianQK added a comment.

> I don't think this is the right way to approach the problem. We should instead extend the existing sinking transform to support sinking instructions from only a subset of predecessors (into a new intermediate block).

Yes, we should extend the sinking common instructions. I noticed that the current sinking operation has already performed the related transformations (a simple subset of predecessors), but it seems to trigger some optimization conflicts.
I made a simple strategy adjustment at D155404 <https://reviews.llvm.org/D155404>.

I will try to address this issue during my next spare time.

> The simple subset of predecessors is:

  define i64 @compare(i64 %a, i64 %b, i64 %c) {
  start:
    switch i64 %c, label %bb0 [
    i64 1, label %bb1
    i64 2, label %bb2
    ]
  
  bb0:                                              ; preds = %start
    %0 = add i64 %a, %b
    br label %exit
  
  bb1:                                              ; preds = %start
    %1 = add i64 %a, %b
    br label %exit
  
  bb2:                                              ; preds = %start
    %2 = add i64 %a, %b
    br label %exit
  
  exit:                                             ; preds = %bb3, %bb2, %bb1, %bb0
    %result = phi i64 [ %0, %bb0 ], [ %1, %bb1 ], [ %2, %bb2 ]
    ret i64 %result
  }

There is another more complex case that can be considered in the future:

  define i64 @compare2(i64 %a, i64 %b, i64 %c) {
  start:
    switch i64 %c, label %bb0 [
    i64 1, label %bb1
    i64 2, label %bb2
    ]
  
  bb0:                                              ; preds = %start
    %0 = add i64 %a, %b
    br label %exit
  
  bb1:                                              ; preds = %start
    %1 = add i64 %a, %b
    br label %exit
  
  bb2:                                              ; preds = %start
    %2 = sub i64 %a, %b                ; here is `sub`
    br label %exit
  
  exit:                                             ; preds = %bb3, %bb2, %bb1, %bb0
    %result = phi i64 [ %0, %bb0 ], [ %1, %bb1 ], [ %2, %bb2 ]
    ret i64 %result
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155395



More information about the llvm-commits mailing list