[MS] Copy the symbols assigned to the former instruction when memory folding.
authorWang, Pengfei <pengfei.wang@intel.com>
Wed, 10 Jun 2020 06:52:54 +0000 (14:52 +0800)
committerWang, Pengfei <pengfei.wang@intel.com>
Wed, 10 Jun 2020 07:38:32 +0000 (15:38 +0800)
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
llvm/test/CodeGen/X86/speculative-load-hardening-no-spill.ll

index 228e3c1..9dbd612 100644 (file)
@@ -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;
   }
 
index bfc2846..f83254b 100644 (file)
@@ -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