Index: lib/Target/ARM/ARMBaseInstrInfo.cpp =================================================================== --- lib/Target/ARM/ARMBaseInstrInfo.cpp +++ lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -2825,8 +2825,11 @@ if (!MI && !SubAdd) return false; - // The single candidate is called MI. - if (!MI) MI = SubAdd; + // If we found a SubAdd, use it as it will be "closer" + if (SubAdd) { + MI = SubAdd; + IsThumb1 = false; + } // We can't use a predicated instruction - it doesn't always write the flags. if (isPredicated(*MI)) Index: test/CodeGen/Thumb2/peephole-addsub.mir =================================================================== --- test/CodeGen/Thumb2/peephole-addsub.mir +++ test/CodeGen/Thumb2/peephole-addsub.mir @@ -29,7 +29,7 @@ tBX_RET 14, $noreg, implicit $r0 # CHECK-LABEL: name: test -# CHECK: %3:gprnopc = t2ADDrr %0, %1, 14, $noreg, def $cpsr -# CHECK-NEXT: %4:gprnopc = t2SUBri %3, 0, 14, $noreg, def dead $cpsr +# CHECK: %3:gprnopc = t2ADDrr %0, %1, 14, $noreg, $noreg +# CHECK-NEXT: %4:gprnopc = t2SUBri %3, 0, 14, $noreg, def $cpsr # CHECK-NEXT: %5:rgpr = t2MOVCCi %2, 0, 7, $cpsr ...