[llvm] [LoongArch] Set isBarrier to true for instruction 'b' (PR #72339)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 19:39:56 PST 2023


https://github.com/zhaoqi5 created https://github.com/llvm/llvm-project/pull/72339

Instr "b offs26" represent to an unconditional branch in LoongArch. Set isBarrier to 1 in tablegen for it, so that MCInstrAnalysis can return correctly.

Fixes https://github.com/llvm/llvm-project/pull/71903.

>From 1089f2b2cc68ab7be7cc9c58d0139f85c246531e Mon Sep 17 00:00:00 2001
From: zhaoqi <zhaoqi01 at loongson.cn>
Date: Fri, 27 Oct 2023 20:25:23 +0800
Subject: [PATCH] [LoongArch] Set isBarrier to true for instruction 'b'

Instr "b offs26" represent to an unconditional branch in LoongArch.
Set isBarrier to 1 in tablegen for it, so that MCInstrAnalysis can
return correctly.

Fixes https://github.com/llvm/llvm-project/pull/71903.
---
 llvm/lib/Target/LoongArch/LoongArchInstrInfo.td         | 1 +
 llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp | 8 ++------
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
index d030fc9aa51ca23..2fea0f33e9eb469 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
@@ -646,6 +646,7 @@ class Br_I26<bits<32> op>
     : FmtI26<op, (outs), (ins simm26_b:$imm26), "$imm26"> {
   let isBranch = 1;
   let isTerminator = 1;
+  let isBarrier = 1;
 }
 } // hasSideEffects = 0, mayLoad = 0, mayStore = 0
 
diff --git a/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp b/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
index 6e1919fc2261c62..468ee79615d643c 100644
--- a/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
+++ b/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
@@ -94,17 +94,13 @@ TEST_P(InstrAnalysisTest, IsBranch) {
 
 TEST_P(InstrAnalysisTest, IsConditionalBranch) {
   EXPECT_TRUE(Analysis->isConditionalBranch(beq()));
-  // FIXME: Instr 'b' is not a ConditionalBranch, so the analysis here is
-  // wrong. The following patch will fix it.
-  EXPECT_TRUE(Analysis->isConditionalBranch(b()));
+  EXPECT_FALSE(Analysis->isConditionalBranch(b()));
   EXPECT_FALSE(Analysis->isConditionalBranch(bl()));
 }
 
 TEST_P(InstrAnalysisTest, IsUnconditionalBranch) {
   EXPECT_FALSE(Analysis->isUnconditionalBranch(beq()));
-  // FIXME: Instr 'b' is an UnconditionalBranch, so the analysis here is
-  // wrong. The following patch will fix it.
-  EXPECT_FALSE(Analysis->isUnconditionalBranch(b()));
+  EXPECT_TRUE(Analysis->isUnconditionalBranch(b()));
   EXPECT_FALSE(Analysis->isUnconditionalBranch(bl()));
   EXPECT_TRUE(Analysis->isUnconditionalBranch(jirl(LoongArch::R0)));
   EXPECT_FALSE(Analysis->isUnconditionalBranch(jirl(LoongArch::R1)));



More information about the llvm-commits mailing list