]> granicus.if.org Git - llvm/commitdiff
X86: Produce @ABS8 symbol modifiers for absolute symbols in range [0,128).
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 2 Feb 2017 00:32:03 +0000 (00:32 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 2 Feb 2017 00:32:03 +0000 (00:32 +0000)
Differential Revision: https://reviews.llvm.org/D28689

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293844 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/MCTargetDesc/X86BaseInfo.h
lib/Target/X86/X86MCInstLower.cpp
lib/Target/X86/X86Subtarget.cpp
test/CodeGen/X86/absolute-rotate.ll

index aab552547fac42df0d5a658191816ccdbb64c5c9..d8953da4abb2dae86b750a7b5f5c40c9fd1e95ea 100644 (file)
@@ -212,7 +212,12 @@ namespace X86II {
     /// the offset from beginning of section.
     ///
     /// This is the TLS offset for the COFF/Windows TLS mechanism.
-    MO_SECREL
+    MO_SECREL,
+
+    /// MO_ABS8 - On a symbol operand this indicates that the symbol is known
+    /// to be an absolute symbol in range [0,128), so we can use the @ABS8
+    /// symbol modifier.
+    MO_ABS8,
   };
 
   enum : uint64_t {
index c7cc1a08237c256d574aac090e031bb9200df0d4..fd4626c494e27103409ff875b93844b6a1599645 100644 (file)
@@ -215,6 +215,7 @@ MCOperand X86MCInstLower::LowerSymbolOperand(const MachineOperand &MO,
   case X86II::MO_GOT:       RefKind = MCSymbolRefExpr::VK_GOT; break;
   case X86II::MO_GOTOFF:    RefKind = MCSymbolRefExpr::VK_GOTOFF; break;
   case X86II::MO_PLT:       RefKind = MCSymbolRefExpr::VK_PLT; break;
+  case X86II::MO_ABS8:      RefKind = MCSymbolRefExpr::VK_X86_ABS8; break;
   case X86II::MO_PIC_BASE_OFFSET:
   case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
     Expr = MCSymbolRefExpr::create(Sym, Ctx);
index 586bb7bd7b1a5539339159700140636411071d2f..69ed925624891fec129d0d8454d1415b9cf372d6 100644 (file)
@@ -15,6 +15,7 @@
 #include "X86InstrInfo.h"
 #include "X86TargetMachine.h"
 #include "llvm/IR/Attributes.h"
+#include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/Support/CommandLine.h"
@@ -93,8 +94,17 @@ unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
     return X86II::MO_NO_FLAG;
 
   // Absolute symbols can be referenced directly.
-  if (GV && GV->isAbsoluteSymbolRef())
-    return X86II::MO_NO_FLAG;
+  if (GV) {
+    if (Optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) {
+      // See if we can use the 8-bit immediate form. Note that some instructions
+      // will sign extend the immediate operand, so to be conservative we only
+      // accept the range [0,128).
+      if (CR->getUnsignedMax().ult(128))
+        return X86II::MO_ABS8;
+      else
+        return X86II::MO_NO_FLAG;
+    }
+  }
 
   if (TM.shouldAssumeDSOLocal(M, GV))
     return classifyLocalReference(GV);
index c0ecb82adc2f54f3a4057e3eb03f3dee20f8bdb7..6240e8d3f76ff043f0c979a27c5f7865b698cde1 100644 (file)
@@ -11,7 +11,7 @@ declare void @f()
 define void @foo(i64 %val) {
   %shr = lshr i64 %val, zext (i8 ptrtoint (i8* @align to i8) to i64)
   %shl = shl i64 %val, zext (i8 sub (i8 64, i8 ptrtoint (i8* @align to i8)) to i64)
-  ; CHECK: rorq $align, %rdi
+  ; CHECK: rorq $align@ABS8, %rdi
   %ror = or i64 %shr, %shl
   %cmp = icmp ult i64 %ror, 109
   br i1 %cmp, label %t, label %f
@@ -24,4 +24,4 @@ f:
   ret void
 }
 
-!0 = !{i64 0, i64 256}
+!0 = !{i64 0, i64 128}