Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch] Set isBarrier to true for instruction 'b' #72339

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

zhaoqi5
Copy link
Contributor

@zhaoqi5 zhaoqi5 commented Nov 15, 2023

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 #71903.

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 llvm#71903.
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 15, 2023

@llvm/pr-subscribers-backend-loongarch

Author: ZhaoQi (zhaoqi5)

Changes

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 #71903.


Full diff: https://github.com/llvm/llvm-project/pull/72339.diff

2 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.td (+1)
  • (modified) llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp (+2-6)
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)));

@zhaoqi5
Copy link
Contributor Author

zhaoqi5 commented Nov 15, 2023

@SixWeining . Looking forward to your review. Thanks.

@SixWeining SixWeining merged commit 42a4d5e into llvm:main Nov 16, 2023
4 checks passed
@zhaoqi5 zhaoqi5 deleted the set-isbarrier-for-instr-b branch November 20, 2023 09:08
sr-tream pushed a commit to sr-tream/llvm-project that referenced this pull request Nov 20, 2023
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 llvm#71903.
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
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 llvm#71903.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants