Skip to content

PR for tstellar/llvm-project#800 #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/test/Driver/undefined-libs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// STDLIB: error: invalid library name in argument '-stdlib=nostdlib'
// STDLIB-EMPTY:

// RUN: not %clangxx --target=i386-unknown-linux -rtlib=nortlib %s 2>&1 | FileCheck --check-prefix=RTLIB %s
// RUN: not %clangxx --target=i386-unknown-linux -rtlib=nortlib --unwindlib=libgcc %s 2>&1 | FileCheck --check-prefix=RTLIB %s
// RTLIB: error: invalid runtime library name in argument '-rtlib=nortlib'
// RTLIB-EMPTY:

Expand Down
9 changes: 0 additions & 9 deletions lld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ if (LLD_DEFAULT_LD_LLD_IS_MINGW)
add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
endif()

option(LLD_DEFAULT_NOSTART_STOP_GC
"Default ld.lld to -z nostart-stop-gc. If ON, C identifier name sections are
forced retained by __start_/__stop_ references. This may increase output size
for many instrumentations, but is compatible with GNU ld newer than 2015-10"
ON)
if (LLD_DEFAULT_NOSTART_STOP_GC)
add_definitions("-DLLD_DEFAULT_NOSTART_STOP_GC=1")
endif()

if (MSVC)
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
Expand Down
9 changes: 0 additions & 9 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,17 +1193,8 @@ static void readConfigs(opt::InputArgList &args) {
config->zSeparate = getZSeparate(args);
config->zShstk = hasZOption(args, "shstk");
config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", 0);
#ifdef LLD_DEFAULT_NOSTART_STOP_GC
// -z start-stop-gc default matches GNU ld<2015-10 and ld64 section$start
// symbols and can decrease file size for many instrumentations. However,
// some users need time to accommodate the -z nostart-stop-gc default, so this
// is added as a temporary workaround.
config->zStartStopGC =
getZFlag(args, "start-stop-gc", "nostart-stop-gc", false);
#else
config->zStartStopGC =
getZFlag(args, "start-stop-gc", "nostart-stop-gc", true);
#endif
config->zStartStopVisibility = getZStartStopVisibility(args);
config->zText = getZFlag(args, "text", "notext", true);
config->zWxneeded = hasZOption(args, "wxneeded");
Expand Down
1 change: 0 additions & 1 deletion lld/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ llvm_canonicalize_cmake_booleans(
LLVM_ENABLE_ZLIB
LLVM_ENABLE_LIBXML2
LLD_DEFAULT_LD_LLD_IS_MINGW
LLD_DEFAULT_NOSTART_STOP_GC
LLVM_HAVE_LIBXAR
)

Expand Down
1 change: 0 additions & 1 deletion lld/test/ELF/gc-sections-metadata-startstop.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# REQUIRES: x86
# UNSUPPORTED: default-nostart-stop-gc
# LINK_ORDER cnamed sections are not kept alive by the __start_* reference.

# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
Expand Down
1 change: 0 additions & 1 deletion lld/test/ELF/gc-sections-startstop-hint.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# REQUIRES: x86
# UNSUPPORTED: default-nostart-stop-gc
## Some projects may not work with GNU ld<2015-10 (ld.lld 13.0.0) --gc-sections behavior.
## Give a hint.

Expand Down
1 change: 0 additions & 1 deletion lld/test/ELF/gc-sections-startstop.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## Check that group members are retained or discarded as a unit.

# REQUIRES: x86
# UNSUPPORTED: default-nostart-stop-gc

# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o --gc-sections -o %t
Expand Down
3 changes: 0 additions & 3 deletions lld/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,3 @@
# ELF tests expect the default target for ld.lld to be ELF.
if config.ld_lld_default_mingw:
config.excludes.append('ELF')

if config.ld_lld_default_nostart_stop_gc:
config.available_features.add('default-nostart-stop-gc')
1 change: 0 additions & 1 deletion lld/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ config.have_libxar = @LLVM_HAVE_LIBXAR@
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
config.ld_lld_default_nostart_stop_gc = @LLD_DEFAULT_NOSTART_STOP_GC@

# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
41 changes: 30 additions & 11 deletions llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2701,29 +2701,29 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
case TargetOpcode::G_ZEXTLOAD:
case TargetOpcode::G_LOAD:
case TargetOpcode::G_STORE: {
GLoadStore &LdSt = cast<GLoadStore>(I);
bool IsZExtLoad = I.getOpcode() == TargetOpcode::G_ZEXTLOAD;
LLT PtrTy = MRI.getType(I.getOperand(1).getReg());
LLT PtrTy = MRI.getType(LdSt.getPointerReg());

if (PtrTy != LLT::pointer(0, 64)) {
LLVM_DEBUG(dbgs() << "Load/Store pointer has type: " << PtrTy
<< ", expected: " << LLT::pointer(0, 64) << '\n');
return false;
}

auto &MemOp = **I.memoperands_begin();
uint64_t MemSizeInBytes = MemOp.getSize();
unsigned MemSizeInBits = MemSizeInBytes * 8;
AtomicOrdering Order = MemOp.getSuccessOrdering();
uint64_t MemSizeInBytes = LdSt.getMemSize();
unsigned MemSizeInBits = LdSt.getMemSizeInBits();
AtomicOrdering Order = LdSt.getMMO().getSuccessOrdering();

// Need special instructions for atomics that affect ordering.
if (Order != AtomicOrdering::NotAtomic &&
Order != AtomicOrdering::Unordered &&
Order != AtomicOrdering::Monotonic) {
assert(I.getOpcode() != TargetOpcode::G_ZEXTLOAD);
assert(!isa<GZExtLoad>(LdSt));
if (MemSizeInBytes > 64)
return false;

if (I.getOpcode() == TargetOpcode::G_LOAD) {
if (isa<GLoad>(LdSt)) {
static unsigned Opcodes[] = {AArch64::LDARB, AArch64::LDARH,
AArch64::LDARW, AArch64::LDARX};
I.setDesc(TII.get(Opcodes[Log2_32(MemSizeInBytes)]));
Expand All @@ -2737,7 +2737,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
}

#ifndef NDEBUG
const Register PtrReg = I.getOperand(1).getReg();
const Register PtrReg = LdSt.getPointerReg();
const RegisterBank &PtrRB = *RBI.getRegBank(PtrReg, MRI, TRI);
// Sanity-check the pointer register.
assert(PtrRB.getID() == AArch64::GPRRegBankID &&
Expand All @@ -2746,13 +2746,31 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
"Load/Store pointer operand isn't a pointer");
#endif

const Register ValReg = I.getOperand(0).getReg();
const Register ValReg = LdSt.getReg(0);
const LLT ValTy = MRI.getType(ValReg);
const RegisterBank &RB = *RBI.getRegBank(ValReg, MRI, TRI);

// The code below doesn't support truncating stores, so we need to split it
// again.
if (isa<GStore>(LdSt) && ValTy.getSizeInBits() > MemSizeInBits) {
unsigned SubReg;
LLT MemTy = LdSt.getMMO().getMemoryType();
auto *RC = getRegClassForTypeOnBank(MemTy, RB, RBI);
if (!getSubRegForClass(RC, TRI, SubReg))
return false;

// Generate a subreg copy.
auto Copy = MIB.buildInstr(TargetOpcode::COPY, {MemTy}, {})
.addReg(ValReg, 0, SubReg)
.getReg(0);
RBI.constrainGenericRegister(Copy, *RC, MRI);
LdSt.getOperand(0).setReg(Copy);
}

// Helper lambda for partially selecting I. Either returns the original
// instruction with an updated opcode, or a new instruction.
auto SelectLoadStoreAddressingMode = [&]() -> MachineInstr * {
bool IsStore = I.getOpcode() == TargetOpcode::G_STORE;
bool IsStore = isa<GStore>(I);
const unsigned NewOpc =
selectLoadStoreUIOp(I.getOpcode(), RB.getID(), MemSizeInBits);
if (NewOpc == I.getOpcode())
Expand All @@ -2769,7 +2787,8 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {

// Folded something. Create a new instruction and return it.
auto NewInst = MIB.buildInstr(NewOpc, {}, {}, I.getFlags());
IsStore ? NewInst.addUse(ValReg) : NewInst.addDef(ValReg);
Register CurValReg = I.getOperand(0).getReg();
IsStore ? NewInst.addUse(CurValReg) : NewInst.addDef(CurValReg);
NewInst.cloneMemRefs(I);
for (auto &Fn : *AddrModeFns)
Fn(NewInst);
Expand Down
115 changes: 115 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/select-store-truncating-float.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=aarch64-- -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
--- |
define void @truncating_f32(double %x) {
%alloca = alloca i32, align 4
%bitcast = bitcast double %x to i64
%trunc = trunc i64 %bitcast to i32
store i32 %trunc, i32* %alloca, align 4
ret void
}

define void @truncating_f16(double %x) {
%alloca = alloca i16, align 2
%bitcast = bitcast double %x to i64
%trunc = trunc i64 %bitcast to i16
store i16 %trunc, i16* %alloca, align 2
ret void
}

define void @truncating_f8(double %x) {
%alloca = alloca i8, align 1
%bitcast = bitcast double %x to i64
%trunc = trunc i64 %bitcast to i8
store i8 %trunc, i8* %alloca, align 1
ret void
}

...
---
name: truncating_f32
alignment: 4
legalized: true
regBankSelected: true
tracksRegLiveness: true
liveins:
- { reg: '$d0' }
frameInfo:
maxAlignment: 4
stack:
- { id: 0, name: alloca, size: 4, alignment: 4 }
machineFunctionInfo: {}
body: |
bb.1 (%ir-block.0):
liveins: $d0

; CHECK-LABEL: name: truncating_f32
; CHECK: liveins: $d0
; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY [[COPY]].ssub
; CHECK: STRSui [[COPY1]], %stack.0.alloca, 0 :: (store (s32) into %ir.alloca)
; CHECK: RET_ReallyLR
%0:fpr(s64) = COPY $d0
%1:gpr(p0) = G_FRAME_INDEX %stack.0.alloca
G_STORE %0(s64), %1(p0) :: (store (s32) into %ir.alloca)
RET_ReallyLR

...
---
name: truncating_f16
alignment: 4
legalized: true
regBankSelected: true
tracksRegLiveness: true
liveins:
- { reg: '$d0' }
frameInfo:
maxAlignment: 2
stack:
- { id: 0, name: alloca, size: 2, alignment: 2 }
machineFunctionInfo: {}
body: |
bb.1 (%ir-block.0):
liveins: $d0

; CHECK-LABEL: name: truncating_f16
; CHECK: liveins: $d0
; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
; CHECK: [[COPY1:%[0-9]+]]:fpr16 = COPY [[COPY]].hsub
; CHECK: STRHui [[COPY1]], %stack.0.alloca, 0 :: (store (s16) into %ir.alloca)
; CHECK: RET_ReallyLR
%0:fpr(s64) = COPY $d0
%1:gpr(p0) = G_FRAME_INDEX %stack.0.alloca
G_STORE %0(s64), %1(p0) :: (store (s16) into %ir.alloca)
RET_ReallyLR

...
---
name: truncating_f8
alignment: 4
legalized: true
regBankSelected: true
tracksRegLiveness: true
liveins:
- { reg: '$d0' }
frameInfo:
maxAlignment: 1
stack:
- { id: 0, name: alloca, size: 1, alignment: 1 }
machineFunctionInfo: {}
body: |
bb.1 (%ir-block.0):
liveins: $d0

; CHECK-LABEL: name: truncating_f8
; CHECK: liveins: $d0
; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
; CHECK: [[COPY1:%[0-9]+]]:fpr8 = COPY [[COPY]].bsub
; CHECK: STRBui [[COPY1]], %stack.0.alloca, 0 :: (store (s8) into %ir.alloca)
; CHECK: RET_ReallyLR
%0:fpr(s64) = COPY $d0
%1:gpr(p0) = G_FRAME_INDEX %stack.0.alloca
G_STORE %0(s64), %1(p0) :: (store (s8) into %ir.alloca)
RET_ReallyLR

...
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ body: |
; CHECK-LABEL: name: test_rule96_id2146_at_idx8070
; CHECK: liveins: $x0
; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
; CHECK: [[LDRBui:%[0-9]+]]:fpr8 = LDRBui [[COPY]], 0 :: (load (s1))
; CHECK: [[LDRBui:%[0-9]+]]:fpr8 = LDRBui [[COPY]], 0 :: (load (s8))
; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY [[LDRBui]]
; CHECK: [[UBFMWri:%[0-9]+]]:gpr32 = UBFMWri [[COPY1]], 0, 0
; CHECK: [[UBFMWri:%[0-9]+]]:gpr32 = UBFMWri [[COPY1]], 0, 7
; CHECK: $noreg = PATCHABLE_RET [[UBFMWri]]
%2:gpr(p0) = COPY $x0
%0:fpr(s1) = G_LOAD %2(p0) :: (load (s1))
%1:gpr(s32) = G_ZEXT %0(s1)
%0:fpr(s8) = G_LOAD %2(p0) :: (load (s8))
%1:gpr(s32) = G_ZEXT %0(s8)
$noreg = PATCHABLE_RET %1(s32)

...
Expand Down