1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}inline_asm: 5*9880d681SAndroid Build Coastguard Worker; CHECK: s_endpgm 6*9880d681SAndroid Build Coastguard Worker; CHECK: s_endpgm 7*9880d681SAndroid Build Coastguard Workerdefine void @inline_asm(i32 addrspace(1)* %out) { 8*9880d681SAndroid Build Coastguard Workerentry: 9*9880d681SAndroid Build Coastguard Worker store i32 5, i32 addrspace(1)* %out 10*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "s_endpgm", ""() 11*9880d681SAndroid Build Coastguard Worker ret void 12*9880d681SAndroid Build Coastguard Worker} 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}inline_asm_shader: 15*9880d681SAndroid Build Coastguard Worker; CHECK: s_endpgm 16*9880d681SAndroid Build Coastguard Worker; CHECK: s_endpgm 17*9880d681SAndroid Build Coastguard Workerdefine amdgpu_ps void @inline_asm_shader() { 18*9880d681SAndroid Build Coastguard Workerentry: 19*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "s_endpgm", ""() 20*9880d681SAndroid Build Coastguard Worker ret void 21*9880d681SAndroid Build Coastguard Worker} 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker; CHECK: {{^}}branch_on_asm: 25*9880d681SAndroid Build Coastguard Worker; Make sure inline assembly is treted as divergent. 26*9880d681SAndroid Build Coastguard Worker; CHECK: s_mov_b32 s{{[0-9]+}}, 0 27*9880d681SAndroid Build Coastguard Worker; CHECK: s_and_saveexec_b64 28*9880d681SAndroid Build Coastguard Workerdefine void @branch_on_asm(i32 addrspace(1)* %out) { 29*9880d681SAndroid Build Coastguard Worker %zero = call i32 asm "s_mov_b32 $0, 0", "=s"() 30*9880d681SAndroid Build Coastguard Worker %cmp = icmp eq i32 %zero, 0 31*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if, label %endif 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Workerif: 34*9880d681SAndroid Build Coastguard Worker store i32 0, i32 addrspace(1)* %out 35*9880d681SAndroid Build Coastguard Worker br label %endif 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Workerendif: 38*9880d681SAndroid Build Coastguard Worker ret void 39*9880d681SAndroid Build Coastguard Worker} 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}v_cmp_asm: 42*9880d681SAndroid Build Coastguard Worker; CHECK: v_mov_b32_e32 [[SRC:v[0-9]+]], s{{[0-9]+}} 43*9880d681SAndroid Build Coastguard Worker; CHECK: v_cmp_ne_i32_e64 s{{\[}}[[MASK_LO:[0-9]+]]:[[MASK_HI:[0-9]+]]{{\]}}, 0, [[SRC]] 44*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: v_mov_b32_e32 v[[V_LO:[0-9]+]], s[[MASK_LO]] 45*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: v_mov_b32_e32 v[[V_HI:[0-9]+]], s[[MASK_HI]] 46*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dwordx2 v{{\[}}[[V_LO]]:[[V_HI]]{{\]}} 47*9880d681SAndroid Build Coastguard Workerdefine void @v_cmp_asm(i64 addrspace(1)* %out, i32 %in) { 48*9880d681SAndroid Build Coastguard Worker %sgpr = tail call i64 asm "v_cmp_ne_i32_e64 $0, 0, $1", "=s,v"(i32 %in) 49*9880d681SAndroid Build Coastguard Worker store i64 %sgpr, i64 addrspace(1)* %out 50*9880d681SAndroid Build Coastguard Worker ret void 51*9880d681SAndroid Build Coastguard Worker} 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm: 54*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 12 55*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm(i32 addrspace(1)* %out) { 56*9880d681SAndroid Build Coastguard Workerentry: 57*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "v_nop_e64", ""() 58*9880d681SAndroid Build Coastguard Worker ret void 59*9880d681SAndroid Build Coastguard Worker} 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker; All inlineasm instructions are assumed to be the maximum size 62*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_small_inst: 63*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 12 64*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_small_inst(i32 addrspace(1)* %out) { 65*9880d681SAndroid Build Coastguard Workerentry: 66*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "v_nop_e32", ""() 67*9880d681SAndroid Build Coastguard Worker ret void 68*9880d681SAndroid Build Coastguard Worker} 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_2_inst: 71*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 20 72*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_2_inst(i32 addrspace(1)* %out) { 73*9880d681SAndroid Build Coastguard Workerentry: 74*9880d681SAndroid Build Coastguard Worker call void asm sideeffect " 75*9880d681SAndroid Build Coastguard Worker v_nop_e64 76*9880d681SAndroid Build Coastguard Worker v_nop_e64 77*9880d681SAndroid Build Coastguard Worker ", ""() 78*9880d681SAndroid Build Coastguard Worker ret void 79*9880d681SAndroid Build Coastguard Worker} 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_2_inst_extra_newline: 82*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 20 83*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_2_inst_extra_newline(i32 addrspace(1)* %out) { 84*9880d681SAndroid Build Coastguard Workerentry: 85*9880d681SAndroid Build Coastguard Worker call void asm sideeffect " 86*9880d681SAndroid Build Coastguard Worker v_nop_e64 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Worker v_nop_e64 89*9880d681SAndroid Build Coastguard Worker ", ""() 90*9880d681SAndroid Build Coastguard Worker ret void 91*9880d681SAndroid Build Coastguard Worker} 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_0_inst: 94*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 95*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_0_inst(i32 addrspace(1)* %out) { 96*9880d681SAndroid Build Coastguard Workerentry: 97*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "", ""() 98*9880d681SAndroid Build Coastguard Worker ret void 99*9880d681SAndroid Build Coastguard Worker} 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_1_comment: 102*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 103*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_1_comment(i32 addrspace(1)* %out) { 104*9880d681SAndroid Build Coastguard Workerentry: 105*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; comment", ""() 106*9880d681SAndroid Build Coastguard Worker ret void 107*9880d681SAndroid Build Coastguard Worker} 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_newline_1_comment: 110*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 111*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_newline_1_comment(i32 addrspace(1)* %out) { 112*9880d681SAndroid Build Coastguard Workerentry: 113*9880d681SAndroid Build Coastguard Worker call void asm sideeffect " 114*9880d681SAndroid Build Coastguard Worker; comment", ""() 115*9880d681SAndroid Build Coastguard Worker ret void 116*9880d681SAndroid Build Coastguard Worker} 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_1_comment_newline: 119*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 120*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_1_comment_newline(i32 addrspace(1)* %out) { 121*9880d681SAndroid Build Coastguard Workerentry: 122*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; comment 123*9880d681SAndroid Build Coastguard Worker", ""() 124*9880d681SAndroid Build Coastguard Worker ret void 125*9880d681SAndroid Build Coastguard Worker} 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_2_comments_line: 128*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 129*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_2_comments_line(i32 addrspace(1)* %out) { 130*9880d681SAndroid Build Coastguard Workerentry: 131*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; first comment ; second comment", ""() 132*9880d681SAndroid Build Coastguard Worker ret void 133*9880d681SAndroid Build Coastguard Worker} 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_2_comments_line_nospace: 136*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 4 137*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_2_comments_line_nospace(i32 addrspace(1)* %out) { 138*9880d681SAndroid Build Coastguard Workerentry: 139*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; first comment;second comment", ""() 140*9880d681SAndroid Build Coastguard Worker ret void 141*9880d681SAndroid Build Coastguard Worker} 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments0: 144*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 20 145*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_mixed_comments0(i32 addrspace(1)* %out) { 146*9880d681SAndroid Build Coastguard Workerentry: 147*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; comment 148*9880d681SAndroid Build Coastguard Worker v_nop_e64 ; inline comment 149*9880d681SAndroid Build Coastguard Worker; separate comment 150*9880d681SAndroid Build Coastguard Worker v_nop_e64 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker ; trailing comment 153*9880d681SAndroid Build Coastguard Worker ; extra comment 154*9880d681SAndroid Build Coastguard Worker ", ""() 155*9880d681SAndroid Build Coastguard Worker ret void 156*9880d681SAndroid Build Coastguard Worker} 157*9880d681SAndroid Build Coastguard Worker 158*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments1: 159*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 20 160*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_mixed_comments1(i32 addrspace(1)* %out) { 161*9880d681SAndroid Build Coastguard Workerentry: 162*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "v_nop_e64 ; inline comment 163*9880d681SAndroid Build Coastguard Worker; separate comment 164*9880d681SAndroid Build Coastguard Worker v_nop_e64 165*9880d681SAndroid Build Coastguard Worker 166*9880d681SAndroid Build Coastguard Worker ; trailing comment 167*9880d681SAndroid Build Coastguard Worker ; extra comment 168*9880d681SAndroid Build Coastguard Worker ", ""() 169*9880d681SAndroid Build Coastguard Worker ret void 170*9880d681SAndroid Build Coastguard Worker} 171*9880d681SAndroid Build Coastguard Worker 172*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments_operands: 173*9880d681SAndroid Build Coastguard Worker; CHECK: codeLenInByte = 20 174*9880d681SAndroid Build Coastguard Workerdefine void @code_size_inline_asm_mixed_comments_operands(i32 addrspace(1)* %out) { 175*9880d681SAndroid Build Coastguard Workerentry: 176*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "; comment 177*9880d681SAndroid Build Coastguard Worker v_add_i32_e32 v0, vcc, v1, v2 ; inline comment 178*9880d681SAndroid Build Coastguard Worker; separate comment 179*9880d681SAndroid Build Coastguard Worker v_bfrev_b32_e32 v0, 1 180*9880d681SAndroid Build Coastguard Worker 181*9880d681SAndroid Build Coastguard Worker ; trailing comment 182*9880d681SAndroid Build Coastguard Worker ; extra comment 183*9880d681SAndroid Build Coastguard Worker ", ""() 184*9880d681SAndroid Build Coastguard Worker ret void 185*9880d681SAndroid Build Coastguard Worker} 186