[llvm] r274405 - TII: Fix inlineasm size counting comments as insts

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 1 16:26:51 PDT 2016


Author: arsenm
Date: Fri Jul  1 18:26:50 2016
New Revision: 274405

URL: http://llvm.org/viewvc/llvm-project?rev=274405&view=rev
Log:
TII: Fix inlineasm size counting comments as insts

The main problem was counting comments on their own
line as instructions.

Modified:
    llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp
    llvm/trunk/test/CodeGen/AMDGPU/inline-asm.ll

Modified: llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp?rev=274405&r1=274404&r2=274405&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp Fri Jul  1 18:26:50 2016
@@ -79,21 +79,25 @@ unsigned TargetInstrInfo::getInlineAsmLe
                                              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<unsigned char>(*Str))) {
-      Length += MAI.getMaxInstLength();
+    } else if (strncmp(Str, MAI.getCommentString(),
+                       strlen(MAI.getCommentString())) == 0) {
+      // Stop counting as an instruction after a comment until the next
+      // separator.
       atInsnStart = false;
     }
-    if (atInsnStart && strncmp(Str, MAI.getCommentString(),
-                               strlen(MAI.getCommentString())) == 0)
+
+    if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) {
+      ++InstCount;
       atInsnStart = false;
+    }
   }
 
-  return Length;
+  return InstCount * MAI.getMaxInstLength();
 }
 
 /// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything

Modified: llvm/trunk/test/CodeGen/AMDGPU/inline-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/inline-asm.ll?rev=274405&r1=274404&r2=274405&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/inline-asm.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/inline-asm.ll Fri Jul  1 18:26:50 2016
@@ -77,3 +77,109 @@ entry:
    ", ""()
   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
+}
+
+; CHECK-LABEL: {{^}}code_size_inline_asm_mixed_comments_operands:
+; CHECK: codeLenInByte = 20
+define void @code_size_inline_asm_mixed_comments_operands(i32 addrspace(1)* %out) {
+entry:
+  call void asm sideeffect "; comment
+    v_add_i32_e32 v0, vcc, v1, v2 ; inline comment
+; separate comment
+    v_bfrev_b32_e32 v0, 1
+
+    ; trailing comment
+    ; extra comment
+  ", ""()
+  ret void
+}




More information about the llvm-commits mailing list