From baa94ef03bccbaf7d973c340d873abdaa4e36479 Mon Sep 17 00:00:00 2001 From: David Green Date: Sun, 17 Mar 2019 21:36:15 +0000 Subject: [ARM] Check that CPSR does not have other uses Fix up rL356335 by checking that CPSR is not read between the compare and the branch. llvm-svn: 356349 --- llvm/lib/Target/ARM/ARMConstantIslandPass.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Target/ARM') diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp index 7aefa01f63d..429c2a582bb 100644 --- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -1912,13 +1912,17 @@ bool ARMConstantIslands::optimizeThumb2Branches() { if (BrOffset >= DestOffset || (DestOffset - BrOffset) > 126) continue; - // Search backwards to the instruction that defines CSPR + // Search backwards to the instruction that defines CSPR. This may or not + // be a CMP, we check that after this loop. If we find an instruction that + // reads cpsr, we need to keep the original cmp. auto *TRI = STI->getRegisterInfo(); MachineBasicBlock::iterator CmpMI = Br.MI; while (CmpMI != Br.MI->getParent()->begin()) { --CmpMI; if (CmpMI->modifiesRegister(ARM::CPSR, TRI)) break; + if (CmpMI->readsRegister(ARM::CPSR, TRI)) + break; } // Check that this inst is a CMP r[0-7], #0 and that the register -- cgit v1.2.3