From 7773c58458157a45df8252322da8a840dc12bfdd Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 4 Aug 2016 14:17:16 +0000 Subject: [PATCH] [Hexagon] Clear kill flags from modified registers in peephole optimizer llvm-svn: 277727 --- llvm/lib/Target/Hexagon/HexagonPeephole.cpp | 5 ++++- llvm/test/CodeGen/Hexagon/peephole-kill-flags.ll | 27 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/Hexagon/peephole-kill-flags.ll diff --git a/llvm/lib/Target/Hexagon/HexagonPeephole.cpp b/llvm/lib/Target/Hexagon/HexagonPeephole.cpp index b064dec..8d1ddeb 100644 --- a/llvm/lib/Target/Hexagon/HexagonPeephole.cpp +++ b/llvm/lib/Target/Hexagon/HexagonPeephole.cpp @@ -250,6 +250,7 @@ bool HexagonPeephole::runOnMachineFunction(MachineFunction &MF) { if (unsigned PeepholeSrc = PeepholeMap.lookup(Reg0)) { // Change the 1st operand and, flip the opcode. MI.getOperand(0).setReg(PeepholeSrc); + MRI->clearKillFlags(PeepholeSrc); int NewOp = QII->getInvertedPredicatedOpcode(MI.getOpcode()); MI.setDesc(QII->get(NewOp)); Done = true; @@ -280,6 +281,7 @@ bool HexagonPeephole::runOnMachineFunction(MachineFunction &MF) { unsigned PSrc = MI.getOperand(PR).getReg(); if (unsigned POrig = PeepholeMap.lookup(PSrc)) { MI.getOperand(PR).setReg(POrig); + MRI->clearKillFlags(POrig); MI.setDesc(QII->get(NewOp)); // Swap operands S1 and S2. MachineOperand Op1 = MI.getOperand(S1); @@ -304,6 +306,7 @@ void HexagonPeephole::ChangeOpInto(MachineOperand &Dst, MachineOperand &Src) { if (Src.isReg()) { Dst.setReg(Src.getReg()); Dst.setSubReg(Src.getSubReg()); + MRI->clearKillFlags(Src.getReg()); } else if (Src.isImm()) { Dst.ChangeToImmediate(Src.getImm()); } else { @@ -316,7 +319,7 @@ void HexagonPeephole::ChangeOpInto(MachineOperand &Dst, MachineOperand &Src) { Dst.setImm(Src.getImm()); } else if (Src.isReg()) { Dst.ChangeToRegister(Src.getReg(), Src.isDef(), Src.isImplicit(), - Src.isKill(), Src.isDead(), Src.isUndef(), + false, Src.isDead(), Src.isUndef(), Src.isDebug()); Dst.setSubReg(Src.getSubReg()); } else { diff --git a/llvm/test/CodeGen/Hexagon/peephole-kill-flags.ll b/llvm/test/CodeGen/Hexagon/peephole-kill-flags.ll new file mode 100644 index 0000000..03de1532 --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/peephole-kill-flags.ll @@ -0,0 +1,27 @@ +; RUN: llc -march=hexagon -verify-machineinstrs < %s | FileCheck %s +; CHECK: memw + +; Check that the testcase compiles without errors. + +target triple = "hexagon" + +; Function Attrs: nounwind +define void @fred() #0 { +entry: + br label %for.cond + +for.cond: ; preds = %entry + %0 = load i32, i32* undef, align 4 + %mul = mul nsw i32 2, %0 + %cmp = icmp slt i32 undef, %mul + br i1 %cmp, label %for.body, label %for.end13 + +for.body: ; preds = %for.cond + unreachable + +for.end13: ; preds = %for.cond + ret void +} + +attributes #0 = { nounwind "target-cpu"="hexagonv60" "target-features"="+hvx,-hvx-double" } + -- 2.7.4