[PATCH] D49778: Fix "Q" and "R" inline assembly template modifiers for big-endian Arm

Jackson Woodruff via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 2 03:01:54 PDT 2018


Jackson updated this revision to Diff 158711.
Jackson marked an inline comment as done.
Jackson added a comment.

Thanks for the reviews.  I have rebased this patch, added a comment to explain what is going on, and removed the redundant curly braces.


https://reviews.llvm.org/D49778

Files:
  lib/Target/ARM/ARMAsmPrinter.cpp
  test/CodeGen/ARM/print-registers-be.ll


Index: test/CodeGen/ARM/print-registers-be.ll
===================================================================
--- /dev/null
+++ test/CodeGen/ARM/print-registers-be.ll
@@ -0,0 +1,8 @@
+; RUN: llc -mtriple=armeb-arm-none-eabi < %s -o -| FileCheck %s
+
+define dso_local void @_Z3fooi(i32 %a) local_unnamed_addr #0 {
+entry:
+; CHECK: @ plain: [[LOW_REG:r[0-9]+]] Q: [[HIGH_REG:r[0-9]+]] R: [[LOW_REG]] H: [[HIGH_REG]]
+  tail call void asm sideeffect "// plain: $0 Q: ${0:Q} R: ${0:R} H: ${0:H}", "r"(i64 1) #1
+  ret void
+}
Index: lib/Target/ARM/ARMAsmPrinter.cpp
===================================================================
--- lib/Target/ARM/ARMAsmPrinter.cpp
+++ lib/Target/ARM/ARMAsmPrinter.cpp
@@ -367,6 +367,18 @@
 
       unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
       unsigned RC;
+      bool FirstHalf;
+      const ARMBaseTargetMachine &ATM =
+        static_cast<const ARMBaseTargetMachine &>(TM);
+
+      // 'Q' should correspond to the low order register and 'R' to the high
+      // order register.  Whether this corresponds to the upper or lower half
+      // depends on the endianess mode.
+      if (ExtraCode[0] == 'Q')
+        FirstHalf = ATM.isLittleEndian();
+      else
+        // ExtraCode[0] == 'R'.
+        FirstHalf = !ATM.isLittleEndian();
       const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
       if (InlineAsm::hasRegClassConstraint(Flags, RC) &&
           ARM::GPRPairRegClass.hasSubClassEq(TRI->getRegClass(RC))) {
@@ -376,14 +388,14 @@
         if (!MO.isReg())
           return true;
         const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
-        unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
+        unsigned Reg = TRI->getSubReg(MO.getReg(), FirstHalf ?
             ARM::gsub_0 : ARM::gsub_1);
         O << ARMInstPrinter::getRegisterName(Reg);
         return false;
       }
       if (NumVals != 2)
         return true;
-      unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
+      unsigned RegOp = FirstHalf ? OpNum : OpNum + 1;
       if (RegOp >= MI->getNumOperands())
         return true;
       const MachineOperand &MO = MI->getOperand(RegOp);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49778.158711.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180802/5ae1bcc5/attachment.bin>


More information about the llvm-commits mailing list