1; RUN: llc -march=amdgcn -verify-machineinstrs -enable-misched -asm-verbose < %s | FileCheck -check-prefix=SI %s 2 3declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone 4 5; SI-LABEL: {{^}}test_if: 6; Make sure the i1 values created by the cfg structurizer pass are 7; moved using VALU instructions 8 9 10; waitcnt should be inserted after exec modification 11; SI: v_cmp_lt_i32_e32 vcc, 0, 12; SI-NEXT: s_and_saveexec_b64 [[SAVE:s\[[0-9]+:[0-9]+\]]], vcc 13; SI-NEXT: s_xor_b64 [[SAVE]], exec, [[SAVE]] 14; SI-NEXT: s_waitcnt lgkmcnt(0) 15; SI-NEXT: ; mask branch [[FLOW_BB:BB[0-9]+_[0-9]+]] 16; SI-NEXT: s_cbranch_execz [[FLOW_BB]] 17 18; SI-NEXT: BB{{[0-9]+}}_1: ; %LeafBlock3 19; SI-NOT: s_mov_b64 s[{{[0-9]:[0-9]}}], -1 20; SI: v_mov_b32_e32 v{{[0-9]}}, -1 21; SI: s_and_saveexec_b64 22; SI-NEXT: s_xor_b64 23; SI-NEXT: ; mask branch 24 25; v_mov should be after exec modification 26; SI: [[FLOW_BB]]: 27; SI-NEXT: s_or_saveexec_b64 [[SAVE]], [[SAVE]] 28; SI-NEXT: v_mov_b32_e32 v{{[0-9]+}} 29; SI-NEXT: s_xor_b64 exec, exec, [[SAVE]] 30; SI-NEXT: ; mask branch 31; 32define void @test_if(i32 %b, i32 addrspace(1)* %src, i32 addrspace(1)* %dst) #1 { 33entry: 34 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone 35 switch i32 %tid, label %default [ 36 i32 0, label %case0 37 i32 1, label %case1 38 ] 39 40case0: 41 %arrayidx1 = getelementptr i32, i32 addrspace(1)* %dst, i32 %b 42 store i32 13, i32 addrspace(1)* %arrayidx1, align 4 43 br label %end 44 45case1: 46 %arrayidx5 = getelementptr i32, i32 addrspace(1)* %dst, i32 %b 47 store i32 17, i32 addrspace(1)* %arrayidx5, align 4 48 br label %end 49 50default: 51 %cmp8 = icmp eq i32 %tid, 2 52 %arrayidx10 = getelementptr i32, i32 addrspace(1)* %dst, i32 %b 53 br i1 %cmp8, label %if, label %else 54 55if: 56 store i32 19, i32 addrspace(1)* %arrayidx10, align 4 57 br label %end 58 59else: 60 store i32 21, i32 addrspace(1)* %arrayidx10, align 4 61 br label %end 62 63end: 64 ret void 65} 66 67; SI-LABEL: @simple_test_v_if 68; SI: v_cmp_ne_u32_e32 vcc, 0, v{{[0-9]+}} 69; SI: s_and_saveexec_b64 [[BR_SREG:s\[[0-9]+:[0-9]+\]]], vcc 70; SI: s_xor_b64 [[BR_SREG]], exec, [[BR_SREG]] 71 72; SI: BB{{[0-9]+_[0-9]+}}: 73; SI: buffer_store_dword 74; SI: s_endpgm 75 76; SI: BB1_2: 77; SI: s_or_b64 exec, exec, [[BR_SREG]] 78; SI: s_endpgm 79define void @simple_test_v_if(i32 addrspace(1)* %dst, i32 addrspace(1)* %src) #1 { 80 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone 81 %is.0 = icmp ne i32 %tid, 0 82 br i1 %is.0, label %store, label %exit 83 84store: 85 %gep = getelementptr i32, i32 addrspace(1)* %dst, i32 %tid 86 store i32 999, i32 addrspace(1)* %gep 87 ret void 88 89exit: 90 ret void 91} 92 93; SI-LABEL: {{^}}simple_test_v_loop: 94; SI: v_cmp_ne_u32_e32 vcc, 0, v{{[0-9]+}} 95; SI: s_and_saveexec_b64 [[BR_SREG:s\[[0-9]+:[0-9]+\]]], vcc 96; SI: s_xor_b64 [[BR_SREG]], exec, [[BR_SREG]] 97; SI: s_cbranch_execz [[LABEL_EXIT:BB[0-9]+_[0-9]+]] 98 99; SI: s_mov_b64 {{s\[[0-9]+:[0-9]+\]}}, 0{{$}} 100 101; SI: [[LABEL_LOOP:BB[0-9]+_[0-9]+]]: 102; SI: buffer_load_dword 103; SI-DAG: buffer_store_dword 104; SI-DAG: v_cmp_eq_u32_e32 vcc, 105; SI-DAG: s_and_b64 vcc, exec, vcc 106; SI: s_cbranch_vccz [[LABEL_LOOP]] 107; SI: [[LABEL_EXIT]]: 108; SI: s_endpgm 109 110define void @simple_test_v_loop(i32 addrspace(1)* %dst, i32 addrspace(1)* %src) #1 { 111entry: 112 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone 113 %is.0 = icmp ne i32 %tid, 0 114 %limit = add i32 %tid, 64 115 br i1 %is.0, label %loop, label %exit 116 117loop: 118 %i = phi i32 [%tid, %entry], [%i.inc, %loop] 119 %gep.src = getelementptr i32, i32 addrspace(1)* %src, i32 %i 120 %gep.dst = getelementptr i32, i32 addrspace(1)* %dst, i32 %i 121 %load = load i32, i32 addrspace(1)* %src 122 store i32 %load, i32 addrspace(1)* %gep.dst 123 %i.inc = add nsw i32 %i, 1 124 %cmp = icmp eq i32 %limit, %i.inc 125 br i1 %cmp, label %exit, label %loop 126 127exit: 128 ret void 129} 130 131; SI-LABEL: {{^}}multi_vcond_loop: 132 133; Load loop limit from buffer 134; Branch to exit if uniformly not taken 135; SI: ; BB#0: 136; SI: buffer_load_dword [[VBOUND:v[0-9]+]] 137; SI: v_cmp_lt_i32_e32 vcc 138; SI: s_and_saveexec_b64 [[OUTER_CMP_SREG:s\[[0-9]+:[0-9]+\]]], vcc 139; SI: s_xor_b64 [[OUTER_CMP_SREG]], exec, [[OUTER_CMP_SREG]] 140; SI: s_cbranch_execz [[LABEL_EXIT:BB[0-9]+_[0-9]+]] 141 142; Initialize inner condition to false 143; SI: BB{{[0-9]+_[0-9]+}}: ; %bb10.preheader 144; SI: s_mov_b64 [[ZERO:s\[[0-9]+:[0-9]+\]]], 0{{$}} 145; SI: s_mov_b64 [[COND_STATE:s\[[0-9]+:[0-9]+\]]], [[ZERO]] 146 147; Clear exec bits for workitems that load -1s 148; SI: [[LABEL_LOOP:BB[0-9]+_[0-9]+]]: 149; SI: buffer_load_dword [[B:v[0-9]+]] 150; SI: buffer_load_dword [[A:v[0-9]+]] 151; SI-DAG: v_cmp_ne_u32_e64 [[NEG1_CHECK_0:s\[[0-9]+:[0-9]+\]]], -1, [[A]] 152; SI-DAG: v_cmp_ne_u32_e32 [[NEG1_CHECK_1:vcc]], -1, [[B]] 153; SI: s_and_b64 [[ORNEG1:s\[[0-9]+:[0-9]+\]]], [[NEG1_CHECK_1]], [[NEG1_CHECK_0]] 154; SI: s_and_saveexec_b64 [[ORNEG2:s\[[0-9]+:[0-9]+\]]], [[ORNEG1]] 155; SI: s_xor_b64 [[ORNEG2]], exec, [[ORNEG2]] 156; SI: s_cbranch_execz [[LABEL_FLOW:BB[0-9]+_[0-9]+]] 157 158; SI: BB{{[0-9]+_[0-9]+}}: ; %bb20 159; SI: buffer_store_dword 160; SI: v_cmp_ge_i64_e32 [[CMP:s\[[0-9]+:[0-9]+\]|vcc]] 161; SI: s_or_b64 [[TMP:s\[[0-9]+:[0-9]+\]]], [[CMP]], [[COND_STATE]] 162 163; SI: [[LABEL_FLOW]]: 164; SI-NEXT: ; in Loop: Header=[[LABEL_LOOP]] 165; SI-NEXT: s_or_b64 exec, exec, [[ORNEG2]] 166; SI-NEXT: s_or_b64 [[COND_STATE]], [[ORNEG2]], [[TMP]] 167; SI-NEXT: s_andn2_b64 exec, exec, [[COND_STATE]] 168; SI-NEXT: s_cbranch_execnz [[LABEL_LOOP]] 169 170; SI: BB#5 171; SI: s_or_b64 exec, exec, [[COND_STATE]] 172 173; SI: [[LABEL_EXIT]]: 174; SI-NOT: [[COND_STATE]] 175; SI: s_endpgm 176 177define void @multi_vcond_loop(i32 addrspace(1)* noalias nocapture %arg, i32 addrspace(1)* noalias nocapture readonly %arg1, i32 addrspace(1)* noalias nocapture readonly %arg2, i32 addrspace(1)* noalias nocapture readonly %arg3) #1 { 178bb: 179 %tmp = tail call i32 @llvm.amdgcn.workitem.id.x() #0 180 %tmp4 = sext i32 %tmp to i64 181 %tmp5 = getelementptr inbounds i32, i32 addrspace(1)* %arg3, i64 %tmp4 182 %tmp6 = load i32, i32 addrspace(1)* %tmp5, align 4 183 %tmp7 = icmp sgt i32 %tmp6, 0 184 %tmp8 = sext i32 %tmp6 to i64 185 br i1 %tmp7, label %bb10, label %bb26 186 187bb10: ; preds = %bb, %bb20 188 %tmp11 = phi i64 [ %tmp23, %bb20 ], [ 0, %bb ] 189 %tmp12 = add nsw i64 %tmp11, %tmp4 190 %tmp13 = getelementptr inbounds i32, i32 addrspace(1)* %arg1, i64 %tmp12 191 %tmp14 = load i32, i32 addrspace(1)* %tmp13, align 4 192 %tmp15 = getelementptr inbounds i32, i32 addrspace(1)* %arg2, i64 %tmp12 193 %tmp16 = load i32, i32 addrspace(1)* %tmp15, align 4 194 %tmp17 = icmp ne i32 %tmp14, -1 195 %tmp18 = icmp ne i32 %tmp16, -1 196 %tmp19 = and i1 %tmp17, %tmp18 197 br i1 %tmp19, label %bb20, label %bb26 198 199bb20: ; preds = %bb10 200 %tmp21 = add nsw i32 %tmp16, %tmp14 201 %tmp22 = getelementptr inbounds i32, i32 addrspace(1)* %arg, i64 %tmp12 202 store i32 %tmp21, i32 addrspace(1)* %tmp22, align 4 203 %tmp23 = add nuw nsw i64 %tmp11, 1 204 %tmp24 = icmp slt i64 %tmp23, %tmp8 205 br i1 %tmp24, label %bb10, label %bb26 206 207bb26: ; preds = %bb10, %bb20, %bb 208 ret void 209} 210 211attributes #0 = { nounwind readnone } 212attributes #1 = { nounwind } 213