1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt < %s -S -mtriple=amdgcn-- -passes=early-cse -earlycse-debug-hash | FileCheck %s
4 ; Should not CSE calls marked as convergent, even if the callee is not convergent.
6 define i32 @test_read_register(i32 %cond) {
7 ; CHECK-LABEL: define i32 @test_read_register
8 ; CHECK-SAME: (i32 [[COND:%.*]]) {
10 ; CHECK-NEXT: [[X1:%.*]] = call i32 @llvm.read_register.i32(metadata [[META0:![0-9]+]]) #[[ATTR2:[0-9]+]]
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[COND]], 0
12 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
14 ; CHECK-NEXT: [[Y1:%.*]] = call i32 @llvm.read_register.i32(metadata [[META0]]) #[[ATTR2]]
15 ; CHECK-NEXT: br label [[END]]
17 ; CHECK-NEXT: [[Y2:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[Y1]], [[IF]] ]
18 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[X1]], [[Y2]]
19 ; CHECK-NEXT: ret i32 [[RET]]
22 ; %x = ballot operation over all lanes.
23 %x1 = call i32 @llvm.read_register.i32(metadata !{!"exec_lo"}) convergent
24 %cmp = icmp eq i32 %cond, 0
25 br i1 %cmp, label %if, label %end
28 ; %y = ballot operation over lanes satisfying %cond.
29 %y1 = call i32 @llvm.read_register.i32(metadata !{!"exec_lo"}) convergent
33 %y2 = phi i32 [0, %entry], [%y1, %if]
34 %ret = add i32 %x1, %y2
38 define i32 @test_read_register_samebb(i32 %cond) {
39 ; CHECK-LABEL: define i32 @test_read_register_samebb
40 ; CHECK-SAME: (i32 [[COND:%.*]]) {
42 ; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.read_register.i32(metadata [[META0]]) #[[ATTR2]]
43 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[X]], [[X]]
44 ; CHECK-NEXT: ret i32 [[RET]]
47 %x = call i32 @llvm.read_register.i32(metadata !{!"exec_lo"}) convergent
48 %y = call i32 @llvm.read_register.i32(metadata !{!"exec_lo"}) convergent
53 define i1 @test_live_mask(i32 %cond) {
54 ; CHECK-LABEL: define i1 @test_live_mask
55 ; CHECK-SAME: (i32 [[COND:%.*]]) {
57 ; CHECK-NEXT: [[X1:%.*]] = call i1 @llvm.amdgcn.live.mask() #[[ATTR2]]
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[COND]], 0
59 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
61 ; CHECK-NEXT: [[Y1:%.*]] = call i1 @llvm.amdgcn.live.mask() #[[ATTR2]]
62 ; CHECK-NEXT: br label [[END]]
64 ; CHECK-NEXT: [[Y2:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[Y1]], [[IF]] ]
65 ; CHECK-NEXT: [[RET:%.*]] = add i1 [[X1]], [[Y2]]
66 ; CHECK-NEXT: ret i1 [[RET]]
69 %x1 = call i1 @llvm.amdgcn.live.mask() convergent
70 %cmp = icmp eq i32 %cond, 0
71 br i1 %cmp, label %if, label %end
74 %y1 = call i1 @llvm.amdgcn.live.mask() convergent
78 %y2 = phi i1 [0, %entry], [%y1, %if]
79 %ret = add i1 %x1, %y2
83 declare i32 @llvm.read_register.i32(metadata)
84 declare i1 @llvm.amdgcn.live.mask()