[llvm] 38348fa - AArch64: treat MC expressions as 2s complement arithmetic.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 8 03:54:58 PDT 2020


Author: Tim Northover
Date: 2020-10-08T11:54:51+01:00
New Revision: 38348fa26548fdcdbc1ae18c6e612d67f103ee37

URL: https://github.com/llvm/llvm-project/commit/38348fa26548fdcdbc1ae18c6e612d67f103ee37
DIFF: https://github.com/llvm/llvm-project/commit/38348fa26548fdcdbc1ae18c6e612d67f103ee37.diff

LOG: AArch64: treat MC expressions as 2s complement arithmetic.

We had a couple of over-zealous diagnostics that meant IR with a reasonable and
valid interpretation was rejected.

Added: 
    llvm/test/CodeGen/AArch64/2s-complement-asm.ll

Modified: 
    llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index dc44980ce218..a355cbf30d31 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -154,19 +154,6 @@ static unsigned AdrImmBits(unsigned Value) {
   return (hi19 << 5) | (lo2 << 29);
 }
 
-static bool valueFitsIntoFixupKind(unsigned Kind, uint64_t Value) {
-  unsigned NumBits;
-  switch(Kind) {
-  case FK_Data_1: NumBits = 8; break;
-  case FK_Data_2: NumBits = 16; break;
-  case FK_Data_4: NumBits = 32; break;
-  case FK_Data_8: NumBits = 64; break;
-  default: return true;
-  }
-  return isUIntN(NumBits, Value) ||
-    isIntN(NumBits, static_cast<int64_t>(Value));
-}
-
 static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
                                  uint64_t Value, MCContext &Ctx,
                                  const Triple &TheTriple, bool IsResolved) {
@@ -341,9 +328,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
   case FK_Data_2:
   case FK_Data_4:
   case FK_Data_8:
-    if (!valueFitsIntoFixupKind(Fixup.getTargetKind(), Value))
-      Ctx.reportError(Fixup.getLoc(), "fixup value too large for data type!");
-    LLVM_FALLTHROUGH;
   case FK_SecRel_2:
   case FK_SecRel_4:
     return Value;

diff  --git a/llvm/test/CodeGen/AArch64/2s-complement-asm.ll b/llvm/test/CodeGen/AArch64/2s-complement-asm.ll
new file mode 100644
index 000000000000..cf646d136020
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/2s-complement-asm.ll
@@ -0,0 +1,9 @@
+; RUN: llc -mtriple=arm64-apple-ios %s -filetype=obj -o - | llvm-objdump --macho --section __DATA,__data - | FileCheck %s
+
+; CHECK: Contents of (__DATA,__data) section
+; CHECK: 0000002a 59ed145d
+ at other = global i32 42
+ at var = global i32 sub(i32 646102975,
+                      i32 add (i32 trunc(i64 sub(i64 ptrtoint(i32* @var to i64),
+                                                         i64 ptrtoint(i32* @other to i64)) to i32),
+                               i32 3432360802))


        


More information about the llvm-commits mailing list