[llvm-branch-commits] [llvm] b067f5e - [GlobalISel][InlineAsm] Fix matching input constraint to physreg

2020-08-07 Thread Hans Wennborg via llvm-branch-commits

Author: Petar Avramovic
Date: 2020-08-07T19:48:51+02:00
New Revision: b067f5eb56684476b5dad4ebd8d6bc5291603d4e

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

LOG: [GlobalISel][InlineAsm] Fix matching input constraint to physreg

Add given input and mark it as tied.
Doesn't create additional copy compared to
matching input constraint to virtual register.

Differential Revision: https://reviews.llvm.org/D85122

(cherry picked from commit d893278bba01b0e1209e8b8accbdd5cfa75a0932)

Added: 


Modified: 
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll

Removed: 




diff  --git a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp 
b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
index 2ce1d414e755..1e2a82615da8 100644
--- a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
@@ -455,19 +455,23 @@ bool InlineAsmLowering::lowerInlineAsm(
 unsigned DefRegIdx = InstFlagIdx + 1;
 Register Def = Inst->getOperand(DefRegIdx).getReg();
 
-// Copy input to new vreg with same reg class as Def
-const TargetRegisterClass *RC = MRI->getRegClass(Def);
 ArrayRef SrcRegs = GetOrCreateVRegs(*OpInfo.CallOperandVal);
 assert(SrcRegs.size() == 1 && "Single register is expected here");
-Register Tmp = MRI->createVirtualRegister(RC);
-if (!buildAnyextOrCopy(Tmp, SrcRegs[0], MIRBuilder))
-  return false;
 
-// Add Flag and input register operand (Tmp) to Inst. Tie Tmp to Def.
+// When Def is physreg: use given input.
+Register In = SrcRegs[0];
+// When Def is vreg: copy input to new vreg with same reg class as Def.
+if (Def.isVirtual()) {
+  In = MRI->createVirtualRegister(MRI->getRegClass(Def));
+  if (!buildAnyextOrCopy(In, SrcRegs[0], MIRBuilder))
+return false;
+}
+
+// Add Flag and input register operand (In) to Inst. Tie In to Def.
 unsigned UseFlag = InlineAsm::getFlagWord(InlineAsm::Kind_RegUse, 1);
 unsigned Flag = InlineAsm::getFlagWordForMatchingOp(UseFlag, DefIdx);
 Inst.addImm(Flag);
-Inst.addReg(Tmp);
+Inst.addReg(In);
 Inst->tieOperands(DefRegIdx, Inst->getNumOperands() - 1);
 break;
   }

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll 
b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
index f8b23ef84721..bfe96827dfe3 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
@@ -243,3 +243,15 @@ define i16 @test_anyext_input_with_matching_constraint() {
   %1 = call i16 asm sideeffect "", "=r,0"(i16 1)
   ret i16 %1
 }
+
+define i64 @test_input_with_matching_constraint_to_physical_register() {
+  ; CHECK-LABEL: name: test_input_with_matching_constraint_to_physical_register
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
+  ; CHECK:   INLINEASM &"", 0 /* attdialect */, 10 /* regdef */, implicit-def 
$x2, 2147483657 /* reguse tiedto:$0 */, [[C]](tied-def 3)(s64)
+  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x2
+  ; CHECK:   $x0 = COPY [[COPY]](s64)
+  ; CHECK:   RET_ReallyLR implicit $x0
+  %1 = tail call i64 asm "", "={x2},0"(i64 0)
+  ret i64 %1
+}



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] 279922f - [ELF] Change tombstone values to (.debug_ranges/.debug_loc) 1 and (other .debug_*) 0

2020-08-07 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-08-07T12:35:09-07:00
New Revision: 279922f108c26fe09667ba2525ab18b4735b28b2

URL: 
https://github.com/llvm/llvm-project/commit/279922f108c26fe09667ba2525ab18b4735b28b2
DIFF: 
https://github.com/llvm/llvm-project/commit/279922f108c26fe09667ba2525ab18b4735b28b2.diff

LOG: [ELF] Change tombstone values to (.debug_ranges/.debug_loc) 1 and (other 
.debug_*) 0

tl;dr See D81784 for the 'tombstone value' concept. This patch changes our 
behavior to be almost the same as GNU ld (except that we also use 1 for 
.debug_loc):

* .debug_ranges & .debug_loc: 1 (LLD<11: 0+addend; GNU ld uses 1 for 
.debug_ranges)
* .debug_*: 0 (LLD<11: 0+addend; GNU ld uses 0; future LLD: -1)

We make the tweaks because:

1) The new tombstone is novel and needs more time to be adopted by consumers 
before it's the default.
2) The old (gold) strategy had problems with zero-length functions - so rather 
than going back that, we're going to the GNU ld strategy which doesn't have 
that problem.
3) One slight tweak to (2) is to apply the .debug_ranges workaround to 
.debug_loc for the same reasons it applies to debug_ranges - to avoid 
terminating lists early.

-

http://lists.llvm.org/pipermail/llvm-dev/2020-July/143482.html

The tombstone value -1 in .debug_line caused problems to lldb (fixed by D83957;
will be included in 11.0.0) and breakpad (fixed by
https://crrev.com/c/2321300). It may potentially affects other DWARF consumers.

For .debug_ranges & .debug_loc: 1, an argument preferring 1 (GNU ld for 
.debug_ranges) over -2 is that:
```
{-1, -2}<<< base address selection entry
{0, length} <<< address range
```
may create a situation where low_pc is greater than high_pc. So we use
1, the GNU ld behavior for .debug_ranges

For other .debug_* sections, there haven't been many reports. One issue is that
bloaty (src/dwarf.cc) can incorrectly count address ranges in .debug_ranges . To
reduce similar disruption, this patch changes the tombstone values to be 
similar to GNU ld.

This does mean another behavior change to the default trunk behavior. Sorry
about it. The default trunk behavior will be similar to release/11.x while we 
work on a transition plan for LLD users.

Reviewed By: dblaikie, echristo

Differential Revision: https://reviews.llvm.org/D84825

(cherry picked from commit 004be4037e1e9c6092323c5c9268acb3ecf9176c)

Added: 


Modified: 
lld/ELF/InputSection.cpp
lld/test/ELF/dead-reloc-in-nonalloc.s
lld/test/ELF/debug-dead-reloc-32.s
lld/test/ELF/debug-dead-reloc-icf.s
lld/test/ELF/debug-dead-reloc-tls-arm.s
lld/test/ELF/debug-dead-reloc-tls.s
lld/test/ELF/debug-dead-reloc.s

Removed: 




diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 7a7ebd974909..a6c97a3506ba 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -938,14 +938,17 @@ void InputSection::relocateNonAlloc(uint8_t *buf, 
ArrayRef rels) {
   // the folded-in function, so exclude .debug_line.
   //
   // For pre-DWARF-v5 .debug_loc and .debug_ranges, -1 is a reserved value
-  // (base address selection entry), so -2 is used.
+  // (base address selection entry), use 1 (which is used by GNU ld for
+  // .debug_ranges).
+  //
+  // TODO To reduce disruption, we use 0 instead of -1 as the tombstone
+  // value. Enable -1 in a future release.
   auto *ds = dyn_cast(&sym);
   if (!sym.getOutputSection() ||
   (ds && ds->section->repl != ds->section && !isDebugLine)) {
 // If -z dead-reloc-in-nonalloc= is specified, respect it.
-const uint64_t value =
-tombstone ? SignExtend64(*tombstone)
-  : (isDebugLocOrRanges ? UINT64_MAX - 1 : UINT64_MAX);
+const uint64_t value = tombstone ? SignExtend64(*tombstone)
+ : (isDebugLocOrRanges ? 1 : 0);
 target->relocateNoSym(bufLoc, type, value);
 continue;
   }

diff  --git a/lld/test/ELF/dead-reloc-in-nonalloc.s 
b/lld/test/ELF/dead-reloc-in-nonalloc.s
index 00d3d2cbc4a8..9e93a0cf32af 100644
--- a/lld/test/ELF/dead-reloc-in-nonalloc.s
+++ b/lld/test/ELF/dead-reloc-in-nonalloc.s
@@ -11,7 +11,7 @@
 # RUN:   -z dead-reloc-in-nonalloc=.not_debug=0x %t.o -o - | cmp %t -
 
 # COMMON:  Contents of section .debug_addr:
-# COMMON-NEXT:   [[ADDR:[0-9a-f]+]]   
+# COMMON-NEXT:   [[ADDR:[0-9a-f]+]]   
 
 # AA:  Contents of section .debug_info:
 # AA-NEXT:   [[ADDR]]   

diff  --git a/lld/test/ELF/debug-dead-reloc-32.s 
b/lld/test/ELF/debug-dead-reloc-32.s
index a7496798c580..b2708a744f28 100644
--- a/lld/test/ELF/debug-dead-reloc-32.s
+++ b/lld/test/ELF/debug-dead-reloc-32.s
@@ -8,11 +8,11 @@
 # RUN: llvm-objdump -s %t | FileCheck %s
 
 # CHECK:  Contents of section .debug_loc:
-# CH