From 6eb9eae0100f13ae2574bd74add915bec0078b4d Mon Sep 17 00:00:00 2001 From: "Wang, Pengfei" Date: Wed, 10 Jun 2020 14:52:54 +0800 Subject: [PATCH] [MS] Copy the symbols assigned to the former instruction when memory folding. The memory folding raplaced the old instruction without copying the symbols assigned. Which will resulted in built fail due to the lost symbols. Reviewed by craig.topper Differential Revision: https://reviews.llvm.org/D78471 --- llvm/lib/CodeGen/TargetInstrInfo.cpp | 4 ++++ llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 228e3c1..9dbd612 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -597,6 +597,10 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI, Flags, MemSize, MFI.getObjectAlign(FI)); NewMI->addMemOperand(MF, MMO); + // The pass "x86 speculative load hardening" always attaches symbols to + // call instructions. We need copy it form old instruction. + NewMI->cloneInstrSymbols(MF, MI); + return NewMI; } diff --git a/llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll b/llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll index bfc2846..f83254b 100644 --- a/llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll +++ b/llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll @@ -2,8 +2,8 @@ define i32 @foo(void ()** %0) { ; CHECK-LABEL: foo: -; CHECK-NOT: .Lslh_ret_addr0: ; CHECK: callq *(%{{.*}}) +; CHECK-NEXT: .Lslh_ret_addr0: ; CHECK-NEXT: movq %rsp, %rcx ; CHECK-NEXT: movq -{{[0-9]+}}(%rsp), %rax ; CHECK-NEXT: sarq $63, %rcx -- 2.7.4