Index: lib/Target/ARM/ARMLoadStoreOptimizer.cpp =================================================================== --- lib/Target/ARM/ARMLoadStoreOptimizer.cpp +++ lib/Target/ARM/ARMLoadStoreOptimizer.cpp @@ -1655,11 +1655,9 @@ ? (isT2 ? (OffImm+4 < 0 ? ARM::t2LDRi8 : ARM::t2LDRi12) : ARM::LDRi12) : (isT2 ? (OffImm+4 < 0 ? ARM::t2STRi8 : ARM::t2STRi12) : ARM::STRi12); DebugLoc dl = MBBI->getDebugLoc(); - // If this is a load and base register is killed, it may have been - // re-defed by the load, make sure the first load does not clobber it. - if (isLd && - (BaseKill || OffKill) && - (TRI->regsOverlap(EvenReg, BaseReg))) { + // If this is a load, make sure the first load does not clobber the base + // register before the second load reads it. + if (isLd && (TRI->regsOverlap(EvenReg, BaseReg))) { assert(!TRI->regsOverlap(OddReg, BaseReg)); InsertLDR_STR(MBB, MBBI, OffImm+4, isLd, dl, NewOpc2, OddReg, OddDeadKill, false, Index: test/CodeGen/ARM/load_store_opt_kill.mir =================================================================== --- /dev/null +++ test/CodeGen/ARM/load_store_opt_kill.mir @@ -0,0 +1,12 @@ +# RUN: llc -mtriple=armv7-none-eabi -verify-machineinstrs -run-pass arm-ldst-opt %s -o - | FileCheck %s +--- +# CHECK-LABEL: name: f +name: f +# Make sure the load into %r0 doesn't clobber the base register before the second load uses it. +# CHECK: %r3 = LDRi12 %r0, 12, 14, _ +# CHECK-NEXT: %r0 = LDRi12 %r0, 8, 14, _ +body: | + bb.0: + liveins: %r0, %r3 + %r0, %r3 = LDRD %r0, %noreg, 8, 14, %noreg +...