Files
clang-p2996/llvm/test/Transforms/SimplifyCFG/AMDGPU/skip-threading.ll
darkbuck ba45453c0a [SimplifyCFG] Skip threading if the target may have divergent branches
- This patch skips the threading on known values if the target has
  divergent branch.
- So far, threading on known values is skipped when the basic block has
  covergent calls. However, even without convergent calls, if that
  condition is divergent, threading duplicates the execution of that
  block threaded and hence results in lower performance. E.g.,
  ```
  BB1:
    if (cond) BB3, BB2

  BB2:
    // work2
    br BB3

  BB3:
    // work3
    if (cond) BB5, BB4

  BB4:
    // work4
    br BB5

  BB5:
  ```

  after threading,

  ```
  BB1:
    if (cond) BB3', BB2'

  BB2':
    // work3
    br BB5

  BB3':
    // work2
    // work3
    // work4
    br BB5

  BB5:

  ```

  After threading, work3 is executed twice if 'cond' is a divergent one.

Reviewers: yxsamliu, nikic

Pull Request: https://github.com/llvm/llvm-project/pull/100185
2024-07-26 12:15:49 -04:00

45 lines
1.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -mtriple=amdgcn -S -passes=simplifycfg < %s | FileCheck %s
declare void @bar1()
declare void @bar2()
declare void @bar3()
define i32 @test_01a(i32 %a) {
; CHECK-LABEL: define i32 @test_01a(
; CHECK-SAME: i32 [[A:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT: br i1 [[COND]], label %[[MERGE:.*]], label %[[IF_FALSE:.*]]
; CHECK: [[IF_FALSE]]:
; CHECK-NEXT: call void @bar1()
; CHECK-NEXT: br label %[[MERGE]]
; CHECK: [[MERGE]]:
; CHECK-NEXT: call void @bar2()
; CHECK-NEXT: br i1 [[COND]], label %[[EXIT:.*]], label %[[IF_FALSE_2:.*]]
; CHECK: [[IF_FALSE_2]]:
; CHECK-NEXT: call void @bar3()
; CHECK-NEXT: br label %[[EXIT]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret i32 [[A]]
;
entry:
%cond = icmp eq i32 %a, 0
br i1 %cond, label %merge, label %if.false
if.false:
call void @bar1()
br label %merge
merge:
call void @bar2()
br i1 %cond, label %exit, label %if.false.2
if.false.2:
call void @bar3()
br label %exit
exit:
ret i32 %a
}