Index: lib/Target/ARM/ARMBaseInstrInfo.cpp =================================================================== --- lib/Target/ARM/ARMBaseInstrInfo.cpp +++ lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -2542,6 +2542,7 @@ return true; case ARM::CMPrr: case ARM::t2CMPrr: + case ARM::tCMPr: SrcReg = MI.getOperand(0).getReg(); SrcReg2 = MI.getOperand(1).getReg(); CmpMask = ~0; @@ -2627,19 +2628,38 @@ OI->getOperand(2).getReg() == SrcReg))) return true; + if (CmpI->getOpcode() == ARM::tCMPr && OI->getOpcode() == ARM::tSUBrr && + ((OI->getOperand(2).getReg() == SrcReg && + OI->getOperand(3).getReg() == SrcReg2) || + (OI->getOperand(2).getReg() == SrcReg2 && + OI->getOperand(3).getReg() == SrcReg))) + return true; + if ((CmpI->getOpcode() == ARM::CMPri || CmpI->getOpcode() == ARM::t2CMPri) && (OI->getOpcode() == ARM::SUBri || OI->getOpcode() == ARM::t2SUBri) && OI->getOperand(1).getReg() == SrcReg && OI->getOperand(2).getImm() == ImmValue) return true; + if (CmpI->getOpcode() == ARM::tCMPi8 && + (OI->getOpcode() == ARM::tSUBi8 || OI->getOpcode() == ARM::tSUBi3) && + OI->getOperand(2).getReg() == SrcReg && + OI->getOperand(3).getImm() == ImmValue) + return true; + if ((CmpI->getOpcode() == ARM::CMPrr || CmpI->getOpcode() == ARM::t2CMPrr) && (OI->getOpcode() == ARM::ADDrr || OI->getOpcode() == ARM::t2ADDrr || OI->getOpcode() == ARM::ADDri || OI->getOpcode() == ARM::t2ADDri) && - OI->getOperand(0).isReg() && OI->getOperand(1).isReg() && OI->getOperand(0).getReg() == SrcReg && OI->getOperand(1).getReg() == SrcReg2) return true; + + if (CmpI->getOpcode() == ARM::tCMPr && + (OI->getOpcode() == ARM::tADDi3 || OI->getOpcode() == ARM::tADDi8) && + OI->getOperand(0).getReg() == SrcReg && + OI->getOperand(2).getReg() == SrcReg2) + return true; + return false; } @@ -2756,7 +2776,8 @@ // For CMPri w/ CmpValue != 0, a SubAdd may still be a candidate. // Thus we cannot return here. if (CmpInstr.getOpcode() == ARM::CMPri || - CmpInstr.getOpcode() == ARM::t2CMPri) + CmpInstr.getOpcode() == ARM::t2CMPri || + CmpInstr.getOpcode() == ARM::tCMPi8) MI = nullptr; else return false; @@ -2894,9 +2915,13 @@ // operands will be modified. unsigned Opc = SubAdd->getOpcode(); bool IsSub = Opc == ARM::SUBrr || Opc == ARM::t2SUBrr || - Opc == ARM::SUBri || Opc == ARM::t2SUBri; - if (!IsSub || (SrcReg2 != 0 && SubAdd->getOperand(1).getReg() == SrcReg2 && - SubAdd->getOperand(2).getReg() == SrcReg)) { + Opc == ARM::SUBri || Opc == ARM::t2SUBri || + Opc == ARM::tSUBrr || Opc == ARM::tSUBi3 || + Opc == ARM::tSUBi8; + unsigned OpI = Opc != ARM::tSUBrr ? 1 : 2; + if (!IsSub || + (SrcReg2 != 0 && SubAdd->getOperand(OpI).getReg() == SrcReg2 && + SubAdd->getOperand(OpI + 1).getReg() == SrcReg)) { // VSel doesn't support condition code update. if (IsInstrVSel) return false; Index: test/CodeGen/Thumb/peephole-cmp.mir =================================================================== --- test/CodeGen/Thumb/peephole-cmp.mir +++ test/CodeGen/Thumb/peephole-cmp.mir @@ -71,9 +71,8 @@ body: | ; CHECK-LABEL: name: test1 ; CHECK: [[COPY:%[0-9]+]]:tgpr = COPY $r0 - ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tADDi3 [[COPY]], 1, 14, $noreg - ; CHECK-NEXT: tCMPr killed [[ADD]], [[COPY]], 14, $noreg, implicit-def $cpsr - ; CHECK-NEXT: tBcc %bb.2, 3, $cpsr + ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tADDi3 [[COPY]], 1, 14, def $cpsr + ; CHECK-NEXT: tBcc %bb.2, 2, $cpsr bb.0 (%ir-block.0): successors: %bb.2(0x40000000), %bb.1(0x40000000) liveins: $r0 @@ -109,9 +108,8 @@ ; CHECK-LABEL: name: test2 ; CHECK: [[COPY1:%[0-9]+]]:tgpr = COPY $r1 ; CHECK-NEXT: [[COPY0:%[0-9]+]]:tgpr = COPY $r0 - ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBrr [[COPY1]], [[COPY0]], 14, $noreg - ; CHECK-NEXT: tCMPr [[COPY0]], [[COPY1]], 14, $noreg, implicit-def $cpsr - ; CHECK-NEXT: tBcc %bb.2, 3, $cpsr + ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBrr [[COPY1]], [[COPY0]], 14, def $cpsr + ; CHECK-NEXT: tBcc %bb.2, 8, $cpsr bb.0 (%ir-block.0): successors: %bb.2(0x40000000), %bb.1(0x40000000) liveins: $r0, $r1 @@ -147,8 +145,7 @@ ; CHECK-LABEL: name: test2b ; CHECK: [[COPY1:%[0-9]+]]:tgpr = COPY $r1 ; CHECK-NEXT: [[COPY0:%[0-9]+]]:tgpr = COPY $r0 - ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBrr [[COPY0]], [[COPY1]], 14, $noreg - ; CHECK-NEXT: tCMPr [[COPY0]], [[COPY1]], 14, $noreg, implicit-def $cpsr + ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBrr [[COPY0]], [[COPY1]], 14, def $cpsr ; CHECK-NEXT: tBcc %bb.2, 3, $cpsr bb.0 (%ir-block.0): successors: %bb.2(0x40000000), %bb.1(0x40000000) @@ -183,8 +180,7 @@ body: | ; CHECK-LABEL: name: test3 ; CHECK: [[COPY:%[0-9]+]]:tgpr = COPY $r0 - ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBi3 [[COPY]], 1, 14, $noreg - ; CHECK-NEXT: tCMPi8 [[COPY0]], 1, 14, $noreg, implicit-def $cpsr + ; CHECK-NEXT: [[ADD:%[0-9]+]]:tgpr, $cpsr = tSUBi3 [[COPY]], 1, 14, def $cpsr ; CHECK-NEXT: tBcc %bb.2, 3, $cpsr bb.0 (%ir-block.0): successors: %bb.2(0x40000000), %bb.1(0x40000000)