Index: lib/CodeGen/TargetInstrInfo.cpp =================================================================== --- lib/CodeGen/TargetInstrInfo.cpp +++ lib/CodeGen/TargetInstrInfo.cpp @@ -79,21 +79,23 @@ const MCAsmInfo &MAI) const { // Count the number of instructions in the asm. bool atInsnStart = true; - unsigned Length = 0; + unsigned InstCount = 0; for (; *Str; ++Str) { if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), - strlen(MAI.getSeparatorString())) == 0) + strlen(MAI.getSeparatorString())) == 0) { atInsnStart = true; - if (atInsnStart && !std::isspace(static_cast(*Str))) { - Length += MAI.getMaxInstLength(); + } else if (strncmp(Str, MAI.getCommentString(), + strlen(MAI.getCommentString())) == 0) { atInsnStart = false; } - if (atInsnStart && strncmp(Str, MAI.getCommentString(), - strlen(MAI.getCommentString())) == 0) + + if (atInsnStart && !std::isspace(static_cast(*Str))) { + ++InstCount; atInsnStart = false; + } } - return Length; + return InstCount * MAI.getMaxInstLength(); } /// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything Index: test/CodeGen/AMDGPU/inline-asm.ll =================================================================== --- test/CodeGen/AMDGPU/inline-asm.ll +++ test/CodeGen/AMDGPU/inline-asm.ll @@ -77,3 +77,94 @@ ", ""() ret void } + +; CHECK-LABEL: {{^}}code_size_inline_asm_2_inst_extra_newline: +; CHECK: codeLenInByte = 20 +define void @code_size_inline_asm_2_inst_extra_newline(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect " + v_nop_e64 + + v_nop_e64 + ", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_0_inst: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_0_inst(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_1_comment: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_1_comment(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "; comment", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_newline_1_comment: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_newline_1_comment(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect " +; comment", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_1_comment_newline: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_1_comment_newline(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "; comment +", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_2_comments_line: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_2_comments_line(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "; first comment ; second comment", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_2_comments_line_nospace: +; CHECK: codeLenInByte = 4 +define void @code_size_inline_asm_2_comments_line_nospace(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "; first comment;second comment", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments0: +; CHECK: codeLenInByte = 20 +define void @code_size_inline_asm_mixed_comments0(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "; comment + v_nop_e64 ; inline comment +; separate comment + v_nop_e64 + + ; trailing comment + ; extra comment + ", ""() + ret void +} + +; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments1: +; CHECK: codeLenInByte = 20 +define void @code_size_inline_asm_mixed_comments1(i32 addrspace(1)* %out) { +entry: + call void asm sideeffect "v_nop_e64 ; inline comment +; separate comment + v_nop_e64 + + ; trailing comment + ; extra comment + ", ""() + ret void +}