[llvm] r324477 - [mips] Support 'y' operand code to print exact log2 of the operand

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 04:36:39 PST 2018


Author: atanasyan
Date: Wed Feb  7 04:36:39 2018
New Revision: 324477

URL: http://llvm.org/viewvc/llvm-project?rev=324477&view=rev
Log:
[mips] Support 'y' operand code to print exact log2 of the operand

Added:
    llvm/trunk/test/CodeGen/Mips/inlineasm-opcode-bad-y.ll
Modified:
    llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
    llvm/trunk/test/CodeGen/Mips/inlineasm-operand-code.ll

Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=324477&r1=324476&r2=324477&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Wed Feb  7 04:36:39 2018
@@ -499,6 +499,13 @@ bool MipsAsmPrinter::PrintAsmOperand(con
         return true;
       O << MO.getImm() - 1;
       return false;
+    case 'y': // exact log2
+      if ((MO.getType()) != MachineOperand::MO_Immediate)
+        return true;
+      if (!isPowerOf2_64(MO.getImm()))
+        return true;
+      O << Log2_64(MO.getImm());
+      return false;
     case 'z':
       // $0 if zero, regular printing otherwise
       if (MO.getType() == MachineOperand::MO_Immediate && MO.getImm() == 0) {

Added: llvm/trunk/test/CodeGen/Mips/inlineasm-opcode-bad-y.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/inlineasm-opcode-bad-y.ll?rev=324477&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/inlineasm-opcode-bad-y.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/inlineasm-opcode-bad-y.ll Wed Feb  7 04:36:39 2018
@@ -0,0 +1,11 @@
+; Negative test for the 'm' operand code. This operand code is applicable
+; for an immediate whic is exact power of 2.
+
+; RUN: not llc -march=mips < %s 2>&1 | FileCheck %s
+
+define i32 @foo() nounwind {
+entry:
+; CHECK: error: invalid operand in inline asm: 'addiu $0, $1, ${2:y}'
+  tail call i32 asm sideeffect "addiu $0, $1, ${2:y}", "=r,r,I"(i32 7, i32 3) ;
+  ret i32 0
+}

Modified: llvm/trunk/test/CodeGen/Mips/inlineasm-operand-code.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/inlineasm-operand-code.ll?rev=324477&r1=324476&r2=324477&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/inlineasm-operand-code.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/inlineasm-operand-code.ll Wed Feb  7 04:36:39 2018
@@ -63,6 +63,17 @@ entry:
   ret i32 0
 }
 
+; y with 4
+define i32 @constraint_y_4() nounwind {
+entry:
+; ALL-LABEL: constraint_y_4:
+; ALL:   #APP
+; ALL:   addiu ${{[0-9]+}}, ${{[0-9]+}}, 2
+; ALL:   #NO_APP
+  tail call i32 asm sideeffect "addiu $0, $1, ${2:y}", "=r,r,I"(i32 7, i32 4) ;
+  ret i32 0
+}
+
 ; z with -3
 define void @constraint_z_0() nounwind {
 entry:




More information about the llvm-commits mailing list