Skip to content

Commit b96c5df

Browse files
authored
[Mips] Add support of MipsInstrInfo::getNop() (#139863)
Fix compile crash when using __builtin_unreachable. Fix #134913.
1 parent ca912c7 commit b96c5df

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

llvm/lib/Target/Mips/MipsInstrInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2727
#include "llvm/IR/DebugInfoMetadata.h"
2828
#include "llvm/IR/DebugLoc.h"
29+
#include "llvm/MC/MCInstBuilder.h"
2930
#include "llvm/MC/MCInstrDesc.h"
3031
#include "llvm/Target/TargetMachine.h"
3132
#include <cassert>
@@ -53,6 +54,13 @@ bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const {
5354
return op.isImm() && op.getImm() == 0;
5455
}
5556

57+
MCInst MipsInstrInfo::getNop() const {
58+
return MCInstBuilder(Mips::SLL)
59+
.addReg(Mips::ZERO)
60+
.addReg(Mips::ZERO)
61+
.addImm(0);
62+
}
63+
5664
/// insertNoop - If data hazard condition is found insert the target nop
5765
/// instruction.
5866
void MipsInstrInfo::

llvm/lib/Target/Mips/MipsInstrInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class MipsInstrInfo : public MipsGenInstrInfo {
5757

5858
explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc);
5959

60+
MCInst getNop() const override;
61+
6062
static const MipsInstrInfo *create(MipsSubtarget &STI);
6163

6264
/// Branch Analysis

llvm/test/CodeGen/Mips/unreachable.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=mipsel-windows-gnu < %s | FileCheck %s -check-prefix=MIPSEL
3+
4+
define void @unreachable() {
5+
; MIPSEL-LABEL: unreachable:
6+
; MIPSEL: # %bb.0: # %entry
7+
; MIPSEL-NEXT: .insn
8+
; MIPSEL-NEXT: nop
9+
10+
entry:
11+
unreachable
12+
}
13+

0 commit comments

Comments
 (0)