[llvm] r257768 - [Hexagon] Handle branches with non-mbb operands

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 07:05:27 PST 2016


Author: kparzysz
Date: Thu Jan 14 09:05:27 2016
New Revision: 257768

URL: http://llvm.org/viewvc/llvm-project?rev=257768&view=rev
Log:
[Hexagon] Handle branches with non-mbb operands

Added:
    llvm/trunk/test/CodeGen/Hexagon/branch-non-mbb.ll
Modified:
    llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp
    llvm/trunk/lib/Target/Hexagon/HexagonNewValueJump.cpp

Modified: llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp?rev=257768&r1=257767&r2=257768&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp Thu Jan 14 09:05:27 2016
@@ -377,6 +377,9 @@ bool HexagonInstrInfo::AnalyzeBranch(Mac
   bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
   bool LastOpcodeHasNVJump = isNewValueJump(LastInst);
 
+  if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB())
+    return true;
+
   // If there is only one terminator instruction, process it.
   if (LastInst && !SecondLastInst) {
     if (LastOpcode == Hexagon::J2_jump) {
@@ -412,6 +415,8 @@ bool HexagonInstrInfo::AnalyzeBranch(Mac
   bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
   bool SecLastOpcodeHasNVJump = isNewValueJump(SecondLastInst);
   if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) {
+    if (!SecondLastInst->getOperand(1).isMBB())
+      return true;
     TBB =  SecondLastInst->getOperand(1).getMBB();
     Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
     Cond.push_back(SecondLastInst->getOperand(0));

Modified: llvm/trunk/lib/Target/Hexagon/HexagonNewValueJump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonNewValueJump.cpp?rev=257768&r1=257767&r2=257768&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonNewValueJump.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonNewValueJump.cpp Thu Jan 14 09:05:27 2016
@@ -485,6 +485,8 @@ bool HexagonNewValueJump::runOnMachineFu
         if (predLive)
           break;
 
+        if (!MI->getOperand(1).isMBB())
+          continue;
         jmpTarget = MI->getOperand(1).getMBB();
         foundJump = true;
         if (MI->getOpcode() == Hexagon::J2_jumpf ||

Added: llvm/trunk/test/CodeGen/Hexagon/branch-non-mbb.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/branch-non-mbb.ll?rev=257768&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/branch-non-mbb.ll (added)
+++ llvm/trunk/test/CodeGen/Hexagon/branch-non-mbb.ll Thu Jan 14 09:05:27 2016
@@ -0,0 +1,46 @@
+; RUN: llc -march=hexagon < %s
+; REQUIRES: asserts
+;
+; The tail calls to foo and bar are branches with functions as operands,
+; instead of basic blocks. Make sure we don't crash on such instructions.
+
+target datalayout = "e-m:e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f64:64:64-f32:32:32-v64:64:64-v32:32:32-a:0-n16:32"
+target triple = "hexagon"
+
+%struct.t0 = type { i8, [2 x i8] }
+%struct.t1 = type { i8, i8, [1900 x i8], %struct.t0 }
+
+ at var = internal global [3 x %struct.t1] zeroinitializer, align 8
+declare void @foo() #2
+declare void @bar(i32, i32) #2
+
+; Function Attrs: nounwind
+define void @fred(i8 signext %a, i8 signext %b) #1 {
+entry:
+  %i = sext i8 %a to i32
+  %t = getelementptr inbounds [3 x %struct.t1], [3 x %struct.t1]* @var, i32 0, i32 %i, i32 3, i32 0
+  %0 = load i8, i8* %t, align 8
+  switch i8 %0, label %if.end14 [
+    i8 1, label %if.then
+    i8 0, label %do.body
+  ]
+
+if.then:                                          ; preds = %entry
+  %j = sext i8 %b to i32
+  %u = getelementptr inbounds [3 x %struct.t1], [3 x %struct.t1]* @var, i32 0, i32 %i, i32 3, i32 1, i32 %j
+  store i8 1, i8* %u, align 1
+  tail call void @foo() #0
+  br label %if.end14
+
+do.body:                                          ; preds = %entry
+  %conv11 = sext i8 %b to i32
+  tail call void @bar(i32 %i, i32 %conv11) #0
+  br label %if.end14
+
+if.end14:                                         ; preds = %entry, %do.body, %if.then
+  ret void
+}
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind "disable-tail-calls"="false" }
+attributes #2 = { "disable-tail-calls"="false" }




More information about the llvm-commits mailing list