Index: llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp =================================================================== --- llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -537,6 +537,18 @@ MachineOperand &PMO = MI.getOperand(PIdx); PMO.setImm(Pred[0].getImm()); MI.getOperand(PIdx+1).setReg(Pred[1].getReg()); + + // Thumb 1 arithmetic instructions do not set CPSR when executed inside an + // IT block. This affects how they are printed. + const MCInstrDesc &MCID = MI.getDesc(); + if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { + assert(MCID.OpInfo[1].isOptionalDef() && "CPSR def isn't expected operand"); + assert((MI.getOperand(1).isDead() || + MI.getOperand(1).getReg() != ARM::CPSR) && + "if conversion tried to stop defining used CPSR"); + MI.getOperand(1).setReg(ARM::NoRegister); + } + return true; } return false; Index: llvm/lib/Target/ARM/ARMInstrFormats.td =================================================================== --- llvm/lib/Target/ARM/ARMInstrFormats.td +++ llvm/lib/Target/ARM/ARMInstrFormats.td @@ -403,8 +403,9 @@ bit isUnaryDataProc = 0; bit canXformTo16Bit = 0; // The instruction is a 16-bit flag setting Thumb instruction. Used - // by the parser to determine whether to require the 'S' suffix on the - // mnemonic (when not in an IT block) or preclude it (when in an IT block). + // by the parser and if-converter to determine whether to require the 'S' + // suffix on the mnemonic (when not in an IT block) or preclude it (when + // in an IT block). bit thumbArithFlagSetting = 0; bit validForTailPredication = 0; Index: llvm/test/CodeGen/ARM/thumb2-it-block.ll =================================================================== --- llvm/test/CodeGen/ARM/thumb2-it-block.ll +++ llvm/test/CodeGen/ARM/thumb2-it-block.ll @@ -16,9 +16,7 @@ ; CHECK: cmp ; CHECK-NEXT: it mi -; We shouldn't need to check for the extra 's' here; tRSB should be printed as -; "rsb" inside an IT block, not "rsbs". -; CHECK-NEXT: rsb{{s?}}mi +; CHECK-NEXT: rsbmi ; CHECK-NEXT: cmp ; CHECK-NEXT: it mi ; CHECK-NEXT: rsb{{s?}}mi Index: llvm/test/CodeGen/Thumb2/ifcvt-rescan-diamonds.ll =================================================================== --- llvm/test/CodeGen/Thumb2/ifcvt-rescan-diamonds.ll +++ llvm/test/CodeGen/Thumb2/ifcvt-rescan-diamonds.ll @@ -22,7 +22,8 @@ ; CHECK-NEXT: it eq ; CHECK-NEXT: ldreq ; CHECK-NEXT: it ne -; CHECK-NEXT: movsne + ; N.b. 16-bit mov instruction in IT block does not set flags. +; CHECK-NEXT: movne ; CHECK-NEXT: mvns ; CHECK-NEXT: b cond.true77: ; preds = %while.cond38