[llvm] r268731 - [mips][mips16] Use isUnconditionalBranch() in AnalyzeBranch() and constant island pass.

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 06:23:52 PDT 2016


Author: dsanders
Date: Fri May  6 08:23:51 2016
New Revision: 268731

URL: http://llvm.org/viewvc/llvm-project?rev=268731&view=rev
Log:
[mips][mips16] Use isUnconditionalBranch() in AnalyzeBranch() and constant island pass.

Summary:
This stops it misidentifying unconditional branches as conditional branches
which fixes a -verify-machineinstrs error about exiting a function via fall through.

Reviewers: sdardis

Subscribers: dsanders, sdardis, llvm-commits

Differential Revision: http://reviews.llvm.org/D19864

Modified:
    llvm/trunk/lib/Target/Mips/MipsConstantIslandPass.cpp
    llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp
    llvm/trunk/test/CodeGen/Mips/brsize3.ll

Modified: llvm/trunk/lib/Target/Mips/MipsConstantIslandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsConstantIslandPass.cpp?rev=268731&r1=268730&r2=268731&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsConstantIslandPass.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsConstantIslandPass.cpp Fri May  6 08:23:51 2016
@@ -97,16 +97,6 @@ static unsigned int branchTargetOperand(
   llvm_unreachable("Unknown branch type");
 }
 
-static bool isUnconditionalBranch(unsigned int Opcode) {
-  switch (Opcode) {
-  default: return false;
-  case Mips::Bimm16:
-  case Mips::BimmX16:
-  case Mips::JalB16:
-    return true;
-  }
-}
-
 static unsigned int longformBranchOpcode(unsigned int Opcode) {
   switch (Opcode) {
   case Mips::Bimm16:
@@ -1615,7 +1605,7 @@ MipsConstantIslands::fixupConditionalBr(
   ++NumCBrFixed;
   if (BMI != MI) {
     if (std::next(MachineBasicBlock::iterator(MI)) == std::prev(MBB->end()) &&
-        isUnconditionalBranch(BMI->getOpcode())) {
+        BMI->isUnconditionalBranch()) {
       // Last MI in the BB is an unconditional branch. Can we simply invert the
       // condition and swap destinations:
       // beqz L1

Modified: llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp?rev=268731&r1=268730&r2=268731&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp Fri May  6 08:23:51 2016
@@ -216,7 +216,7 @@ MipsInstrInfo::BranchType MipsInstrInfo:
   // If there is only one terminator instruction, process it.
   if (!SecondLastOpc) {
     // Unconditional branch.
-    if (LastOpc == UncondBrOpc) {
+    if (LastInst->isUnconditionalBranch()) {
       TBB = LastInst->getOperand(0).getMBB();
       return BT_Uncond;
     }
@@ -235,7 +235,7 @@ MipsInstrInfo::BranchType MipsInstrInfo:
 
   // If second to last instruction is an unconditional branch,
   // analyze it and remove the last instruction.
-  if (SecondLastOpc == UncondBrOpc) {
+  if (SecondLastInst->isUnconditionalBranch()) {
     // Return if the last instruction cannot be removed.
     if (!AllowModify)
       return BT_None;
@@ -248,7 +248,7 @@ MipsInstrInfo::BranchType MipsInstrInfo:
 
   // Conditional branch followed by an unconditional branch.
   // The last one must be unconditional.
-  if (LastOpc != UncondBrOpc)
+  if (!LastInst->isUnconditionalBranch())
     return BT_None;
 
   AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);

Modified: llvm/trunk/test/CodeGen/Mips/brsize3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/brsize3.ll?rev=268731&r1=268730&r2=268731&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/brsize3.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/brsize3.ll Fri May  6 08:23:51 2016
@@ -1,6 +1,12 @@
-; RUN: llc -mtriple=mipsel-linux-gnu -march=mipsel -mattr=mips16 -mattr=+soft-float -mips16-hard-float -relocation-model=pic -mips16-constant-islands   < %s | FileCheck %s -check-prefix=b-no-short
+; RUN: llc -mtriple=mipsel-linux-gnu -march=mipsel -mattr=mips16 \
+; RUN:     -mattr=+soft-float -mips16-hard-float -relocation-model=pic \
+; RUN:     -mips16-constant-islands -verify-machineinstrs  < %s | \
+; RUN:     FileCheck %s -check-prefix=b-no-short
 
-; RUN: llc -mtriple=mipsel-linux-gnu -march=mipsel -mattr=mips16 -mattr=+soft-float -mips16-hard-float -relocation-model=pic -mips16-constant-islands   < %s | FileCheck %s -check-prefix=b-long
+; RUN: llc -mtriple=mipsel-linux-gnu -march=mipsel -mattr=mips16 \
+; RUN:     -mattr=+soft-float -mips16-hard-float -relocation-model=pic \
+; RUN:     -mips16-constant-islands -verify-machineinstrs < %s | \
+; RUN:     FileCheck %s -check-prefix=b-long
 
 ; ModuleID = 'brsize3.c'
 target datalayout = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32-S64"




More information about the llvm-commits mailing list