[llvm] r301698 - [Hexagon] Do not move a block if it is on a fall-through path
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 14:54:12 PDT 2017
Author: kparzysz
Date: Fri Apr 28 16:54:11 2017
New Revision: 301698
URL: http://llvm.org/viewvc/llvm-project?rev=301698&view=rev
Log:
[Hexagon] Do not move a block if it is on a fall-through path
Added:
llvm/trunk/test/CodeGen/Hexagon/cfgopt-fall-through.ll
Modified:
llvm/trunk/lib/Target/Hexagon/HexagonCFGOptimizer.cpp
Modified: llvm/trunk/lib/Target/Hexagon/HexagonCFGOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonCFGOptimizer.cpp?rev=301698&r1=301697&r2=301698&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonCFGOptimizer.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonCFGOptimizer.cpp Fri Apr 28 16:54:11 2017
@@ -38,6 +38,7 @@ class HexagonCFGOptimizer : public Machi
private:
void InvertAndChangeJumpTarget(MachineInstr &, MachineBasicBlock *);
+ bool isOnFallThroughPath(MachineBasicBlock *MBB);
public:
static char ID;
@@ -106,6 +107,14 @@ void HexagonCFGOptimizer::InvertAndChang
MI.getOperand(1).setMBB(NewTarget);
}
+bool HexagonCFGOptimizer::isOnFallThroughPath(MachineBasicBlock *MBB) {
+ if (MBB->canFallThrough())
+ return true;
+ for (MachineBasicBlock *PB : MBB->predecessors())
+ if (PB->isLayoutSuccessor(MBB) && PB->canFallThrough())
+ return true;
+ return false;
+}
bool HexagonCFGOptimizer::runOnMachineFunction(MachineFunction &Fn) {
if (skipFunction(*Fn.getFunction()))
@@ -182,7 +191,6 @@ bool HexagonCFGOptimizer::runOnMachineFu
}
if ((NumSuccs == 2) && LayoutSucc && (LayoutSucc->pred_size() == 1)) {
-
// Ensure that BB2 has one instruction -- an unconditional jump.
if ((LayoutSucc->size() == 1) &&
IsUnconditionalJump(LayoutSucc->front().getOpcode())) {
@@ -211,9 +219,8 @@ bool HexagonCFGOptimizer::runOnMachineFu
JumpAroundTarget->moveAfter(LayoutSucc);
// only move a block if it doesn't have a fall-thru. otherwise
// the CFG will be incorrect.
- if (!UncondTarget->canFallThrough()) {
+ if (!isOnFallThroughPath(UncondTarget))
UncondTarget->moveAfter(JumpAroundTarget);
- }
}
//
Added: llvm/trunk/test/CodeGen/Hexagon/cfgopt-fall-through.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/cfgopt-fall-through.ll?rev=301698&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/cfgopt-fall-through.ll (added)
+++ llvm/trunk/test/CodeGen/Hexagon/cfgopt-fall-through.ll Fri Apr 28 16:54:11 2017
@@ -0,0 +1,71 @@
+; RUN: llc -march=hexagon -verify-machineinstrs < %s | FileCheck %s
+; REQUIRES: asserts
+
+; Check for some sane output. This test used to crash.
+; CHECK: jumpr r31
+
+
+define i32 @fred(i32 %a0, i8 zeroext %a1) local_unnamed_addr #0 {
+b2:
+ br i1 undef, label %b4, label %b3
+
+b3: ; preds = %b2
+ unreachable
+
+b4: ; preds = %b2
+ br i1 undef, label %b19, label %b5
+
+b5: ; preds = %b4
+ br i1 undef, label %b6, label %b12
+
+b6: ; preds = %b5
+ switch i8 %a1, label %b17 [
+ i8 2, label %b7
+ i8 5, label %b7
+ i8 1, label %b7
+ i8 3, label %b8
+ ]
+
+b7: ; preds = %b6, %b6, %b6
+ unreachable
+
+b8: ; preds = %b6
+ br i1 undef, label %b11, label %b9
+
+b9: ; preds = %b8
+ %v10 = or i32 undef, 0
+ br label %b15
+
+b11: ; preds = %b8
+ unreachable
+
+b12: ; preds = %b5
+ switch i8 %a1, label %b17 [
+ i8 5, label %b13
+ i8 1, label %b13
+ i8 2, label %b14
+ i8 3, label %b15
+ ]
+
+b13: ; preds = %b12, %b12
+ store i32 %a0, i32* undef, align 4
+ br label %b17
+
+b14: ; preds = %b12
+ store i16 undef, i16* undef, align 4
+ br label %b17
+
+b15: ; preds = %b12, %b9
+ %v16 = phi i32 [ 0, %b12 ], [ %v10, %b9 ]
+ store i32 undef, i32* undef, align 4
+ br label %b17
+
+b17: ; preds = %b15, %b14, %b13, %b12, %b6
+ %v18 = phi i32 [ 0, %b13 ], [ 0, %b12 ], [ %v16, %b15 ], [ 0, %b14 ], [ 0, %b6 ]
+ ret i32 %v18
+
+b19: ; preds = %b4
+ unreachable
+}
+
+attributes #0 = { nounwind "target-cpu"="hexagonv55" "target-features"="-hvx,-hvx-double,-long-calls" }
More information about the llvm-commits
mailing list