Skip to content

[Mips] Do not emit teq if NoZeroDivCheck in FastISel#204386

Open
xry111 wants to merge 1 commit into
llvm:mainfrom
xry111:xry111/mips-div-no-trap-O0
Open

[Mips] Do not emit teq if NoZeroDivCheck in FastISel#204386
xry111 wants to merge 1 commit into
llvm:mainfrom
xry111:xry111/mips-div-no-trap-O0

Conversation

@xry111

@xry111 xry111 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Fix the issue: -mno-check-zero-division is not respected at -O0 for some test cases.

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-mips

Author: Xi Ruoyao (xry111)

Changes

Fix the issue: -mno-check-zero-division is not respected at -O0 for some test cases.


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

2 Files Affected:

  • (modified) llvm/lib/Target/Mips/MipsFastISel.cpp (+4-2)
  • (modified) llvm/test/CodeGen/Mips/divrem.ll (+2)
diff --git a/llvm/lib/Target/Mips/MipsFastISel.cpp b/llvm/lib/Target/Mips/MipsFastISel.cpp
index 9645fb5293609..ab76ee069fb15 100644
--- a/llvm/lib/Target/Mips/MipsFastISel.cpp
+++ b/llvm/lib/Target/Mips/MipsFastISel.cpp
@@ -74,6 +74,7 @@
 using namespace llvm;
 
 extern cl::opt<bool> EmitJalrReloc;
+extern cl::opt<bool> NoZeroDivCheck;
 
 namespace {
 
@@ -1952,8 +1953,9 @@ bool MipsFastISel::selectDivRem(const Instruction *I, unsigned ISDOpcode) {
     return false;
 
   emitInst(DivOpc).addReg(Src0Reg).addReg(Src1Reg);
-  if (!isa<ConstantInt>(I->getOperand(1)) ||
-      dyn_cast<ConstantInt>(I->getOperand(1))->isZero()) {
+  if (!NoZeroDivCheck &&
+      (!isa<ConstantInt>(I->getOperand(1)) ||
+       dyn_cast<ConstantInt>(I->getOperand(1))->isZero())) {
     emitInst(Mips::TEQ).addReg(Src1Reg).addReg(Mips::ZERO).addImm(7);
   }
 
diff --git a/llvm/test/CodeGen/Mips/divrem.ll b/llvm/test/CodeGen/Mips/divrem.ll
index a29f2793c081f..e30764fef9042 100644
--- a/llvm/test/CodeGen/Mips/divrem.ll
+++ b/llvm/test/CodeGen/Mips/divrem.ll
@@ -12,6 +12,8 @@
 ; RUN: llc -mtriple=mips64 -mcpu=mips64r2 -mno-check-zero-division -relocation-model=pic < %s | FileCheck %s -check-prefixes=ALL,ACC64,NOCHECK
 ; RUN: llc -mtriple=mips64 -mcpu=mips64r6 -mno-check-zero-division -relocation-model=pic < %s | FileCheck %s -check-prefixes=ALL,GPR64,NOCHECK
 
+; RUN: llc -mtriple=mipsel -mcpu=mips32 -O0 -mno-check-zero-division -relocation-model=pic < %s | FileCheck %s -check-prefixes=NOCHECK
+
 ; FileCheck Prefixes:
 ;   ALL - All targets
 ;   ACC32 - Accumulator based multiply/divide on 32-bit targets

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@xry111 xry111 force-pushed the xry111/mips-div-no-trap-O0 branch from 86a27b4 to 51a7b24 Compare June 17, 2026 17:25
@folkertdev folkertdev requested a review from yingopq June 17, 2026 17:50
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 197071 tests passed
  • 5396 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 135989 tests passed
  • 3458 tests skipped

✅ The build succeeded and all tests passed.

@folkertdev

Copy link
Copy Markdown
Contributor

Looks like LLVM main is currently broken. That'll probably get resolved within a couple of hours (or maybe it has been already). You can merge current main to re-trigger a CI build (also a rebase is probably fine for a PR this small).

Fix the issue: -mno-check-zero-division is not respected at -O0 for
some test cases.
@xry111 xry111 force-pushed the xry111/mips-div-no-trap-O0 branch from 51a7b24 to 6d41c9c Compare June 18, 2026 10:26
@yingopq

yingopq commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LGTM.

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.

3 participants