[PATCH] D155711: [SimplifyCFG] Hoist common instructions on Switch.

DianQK via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 07:31:53 PDT 2023


DianQK created this revision.
DianQK added reviewers: nikic, StephenFan, xbolva00.
Herald added subscribers: khei4, hiraditya.
Herald added a project: All.
DianQK requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Sink common instructions are not always performance friendly. We need to implement hoist common instructions on switch instruction to solve the following problem:

  define i1 @foo(i64 %a, i64 %b, i64 %c, i64 %d) {
  start:
    %test = icmp eq i64 %a, %d
    br i1 %test, label %switch_bb, label %exit
  
  switch_bb:                                        ; preds = %start
    switch i64 %a, label %bb0 [
      i64 1, label %bb1
      i64 2, label %bb2
    ]
  
  bb0:                                              ; preds = %switch_bb
    %0 = icmp eq i64 %b, %c
    br label %exit
  
  bb1:                                              ; preds = %switch_bb
    %1 = icmp eq i64 %b, %c
    br label %exit
  
  bb2:                                              ; preds = %switch_bb
    %2 = icmp eq i64 %b, %c
    br label %exit
  
  exit:                                             ; preds = %bb2, %bb1, %bb0, %start
    %result = phi i1 [ false, %start ], [ %0, %bb0 ], [ %1, %bb1 ], [ %2, %bb2 ]
    ret i1 %result
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155711

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/hoist-common-code-on-switch.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155711.542023.patch
Type: text/x-patch
Size: 4262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230719/9c671863/attachment.bin>


More information about the llvm-commits mailing list