blob: cfba82feafba7784f36b6fc9fbcb67413a48eca5 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -S -mtriple=amdgpu-unknown-amdpal -passes=indvars < %s | FileCheck %s
; Lanes killed inside the loop never reach the exit block. Sinking the ballot
; there would make it see only the surviving lanes instead of all lanes that
; executed the preheader.
define amdgpu_ps i32 @ballot_before_kill_loop(i1 %live, i32 %n) {
; CHECK-LABEL: define amdgpu_ps i32 @ballot_before_kill_loop(
; CHECK-SAME: i1 [[LIVE:%.*]], i32 [[N:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: [[BALLOT:%.*]] = call i32 @llvm.amdgcn.ballot.i32(i1 true)
; CHECK-NEXT: [[UMAX:%.*]] = call i32 @llvm.umax.i32(i32 [[N]], i32 1)
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LOOP]] ]
; CHECK-NEXT: call void @llvm.amdgcn.kill(i1 [[LIVE]])
; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], [[UMAX]]
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[LOOP]], label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret i32 [[BALLOT]]
;
entry:
%ballot = call i32 @llvm.amdgcn.ballot.i32(i1 true)
br label %loop
loop:
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
call void @llvm.amdgcn.kill(i1 %live)
%i.next = add i32 %i, 1
%cmp = icmp ult i32 %i.next, %n
br i1 %cmp, label %loop, label %exit
exit:
ret i32 %ballot
}
declare i32 @llvm.amdgcn.ballot.i32(i1)
declare void @llvm.amdgcn.kill(i1)