[MC] Use LShr for constant evaluation of ">>" on ELF/arm64--darwin.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 28 Apr 2015 01:37:11 +0000 (01:37 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 28 Apr 2015 01:37:11 +0000 (01:37 +0000)
This matches other assemblers and is less unexpected (e.g. PR23227).
On ELF, I tried binutils gas v2.24 and nasm 2.10.09, and they both
agree on LShr.  On COFF, I couldn't get my hands on an assembler yet,
so don't change the behavior.  For now, don't change it on non-AArch64
Darwin either, as the other assembler is gas v1.38, which does an AShr.

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

lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoCOFF.cpp
lib/MC/MCAsmInfoDarwin.cpp
lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.cpp
test/MC/AArch64/expr-shr.s [new file with mode: 0644]
test/MC/ARM/bracket-exprs.s
test/MC/AsmParser/expr-shr.s [new file with mode: 0644]
test/MC/ELF/bracket-exprs.s

index 22de8bd13dcbdb2578c50db23919de838ca64077..1a45b5a389f649f373c279f5eb75a6303f21eca3 100644 (file)
@@ -90,7 +90,7 @@ MCAsmInfo::MCAsmInfo() {
   DwarfRegNumForCFI = false;
   NeedsDwarfSectionOffsetDirective = false;
   UseParensForSymbolVariant = false;
-  UseLogicalShr = false;
+  UseLogicalShr = true;
 
   // FIXME: Clang's logic should be synced with the logic used to initialize
   //        this member and the two implementations should be merged.
index bb3f0d3a42973530655023f8c1061edfa424acdf..97fc76a9adb19a899392db8d158eca388bb43e68 100644 (file)
@@ -36,6 +36,10 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
   NeedsDwarfSectionOffsetDirective = true;
 
   UseIntegratedAssembler = true;
+
+  // FIXME: For now keep the previous behavior, AShr. Need to double-check
+  // other COFF-targeting assemblers and change this if necessary.
+  UseLogicalShr = false;
 }
 
 void MCAsmInfoMicrosoft::anchor() { }
index ae9486d3db4de9c535af8cc9c0c1667faaa45559..bb90ff2c350ae7bda091ceec5f3b38d7ac203003 100644 (file)
@@ -93,4 +93,9 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
 
   UseIntegratedAssembler = true;
   SetDirectiveSuppressesReloc = true;
+
+  // FIXME: For now keep the previous behavior, AShr, matching the previous
+  // behavior of as(1) (both -q and -Q: resp. LLVM and gas v1.38).
+  // If/when this changes, the AArch64 Darwin special case can go away.
+  UseLogicalShr = false;
 }
index f048474fd4a9999da0d6a2968184c3a41b5ccfc7..c41220400410290a0e4f47056b3bb2785a27f319 100644 (file)
@@ -48,6 +48,10 @@ AArch64MCAsmInfoDarwin::AArch64MCAsmInfoDarwin() {
   UseDataRegionDirectives = true;
 
   ExceptionsType = ExceptionHandling::DwarfCFI;
+
+  // AArch64 Darwin doesn't have the baggage of X86/ARM, so it's fine to use
+  // LShr instead of AShr.
+  UseLogicalShr = true;
 }
 
 const MCExpr *AArch64MCAsmInfoDarwin::getExprForPersonalitySymbol(
diff --git a/test/MC/AArch64/expr-shr.s b/test/MC/AArch64/expr-shr.s
new file mode 100644 (file)
index 0000000..aa23878
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: llvm-mc -triple aarch64-unknown-unknown-elf %s | FileCheck %s --check-prefix=ELF
+// RUN: llvm-mc -triple aarch64-unknown-darwin %s | FileCheck %s --check-prefix=DARWIN
+
+.data
+
+// ELF: .xword 3
+// DARWIN: .quad 3
+.quad (~0 >> 62)
index 922bf7037019e60e6a16af91ae2288b6dd406531..74f3323cd2d527fd70157b409a7fde4396e9d583 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: llvm-mc -triple arm-unknown-linux %s | FileCheck %s
 
 // CHECK: .byte 1
-.if [~0 >> 1] == -1
+.if [~0 >> 63] == 1
 .byte 1
 .else
 .byte 2
diff --git a/test/MC/AsmParser/expr-shr.s b/test/MC/AsmParser/expr-shr.s
new file mode 100644 (file)
index 0000000..fc117b6
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown-elf %s | FileCheck %s --check-prefix=CHECK
+// RUN: llvm-mc -triple x86_64-pc-windows-msvc %s | FileCheck %s --check-prefix=MSVC
+// RUN: llvm-mc -triple x86_64-unknown-darwin %s | FileCheck %s --check-prefix=DARWIN
+
+.data
+
+// CHECK: .quad 3
+
+// Both COFF and Darwin still use AShr.
+// MSVC: .quad -1
+// DARWIN: .quad -1
+
+.quad (~0 >> 62)
index 96f9f9aa450aa61968eb6fdbae09918fbf6aed17..e7299fde700920d1ffdd4a3d96fe09f348c4a3d9 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
 
 // CHECK: .byte 1
-.if [~0 >> 1] == -1
+.if [~0 >> 63] == 1
 .byte 1
 .else
 .byte 2