Index: llvm/trunk/lib/Target/ARM/ARMFastISel.cpp =================================================================== --- llvm/trunk/lib/Target/ARM/ARMFastISel.cpp +++ llvm/trunk/lib/Target/ARM/ARMFastISel.cpp @@ -2970,12 +2970,16 @@ unsigned ConstAlign = MF->getDataLayout().getPrefTypeAlignment(Type::getInt32PtrTy(*Context)); unsigned Idx = MF->getConstantPool()->getConstantPoolIndex(CPV, ConstAlign); + MachineMemOperand *CPMMO = + MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(*MF), + MachineMemOperand::MOLoad, 4, 4); unsigned TempReg = MF->getRegInfo().createVirtualRegister(&ARM::rGPRRegClass); unsigned Opc = isThumb2 ? ARM::t2LDRpci : ARM::LDRcp; MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), TempReg) - .addConstantPoolIndex(Idx); + .addConstantPoolIndex(Idx) + .addMemOperand(CPMMO); if (Opc == ARM::LDRcp) MIB.addImm(0); MIB.add(predOps(ARMCC::AL)); @@ -2988,6 +2992,7 @@ MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg) .addReg(TempReg) .addImm(ARMPCLabelIndex); + if (!Subtarget->isThumb()) MIB.add(predOps(ARMCC::AL)); Index: llvm/trunk/test/CodeGen/ARM/ldrcppic.ll =================================================================== --- llvm/trunk/test/CodeGen/ARM/ldrcppic.ll +++ llvm/trunk/test/CodeGen/ARM/ldrcppic.ll @@ -0,0 +1,56 @@ +; The failure is caused by ARM LDRcp/PICADD pairs. In PIC mode, the constant pool +; need a label to do address computation. This label is emitted when backend emits +; PICADD. When the target becomes dead, PICADD will be deleted. without this patch +; LDRcp is dead but not being deleted. This will cause a dead contant pool entry +; using a non existing label. This will cause an error in MC object emitting pass. + +; RUN: llc -relocation-model=pic -mcpu=cortex-a53 %s -filetype=obj -o - | llvm-nm - | FileCheck %s + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "armv8-unknown-linux-android" + +@_ZN15UsecaseSelector25AllowedImplDefinedFormatsE = external dso_local unnamed_addr constant <{ i32, i32, i32, i32, [12 x i32] }>, align 4 + +; Function Attrs: noinline nounwind optnone sspstrong uwtable +define dso_local fastcc void @_ZN15UsecaseSelector26IsAllowedImplDefinedFormatE15ChiBufferFormatj() unnamed_addr #1 align 2 { + br label %1 + +;