[PATCH] D114581: [RISCV] Fix a crash in decoding LMUL in VTYPE
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 25 07:49:28 PST 2021
benshi001 updated this revision to Diff 389795.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114581/new/
https://reviews.llvm.org/D114581
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/test/tools/llvm-objdump/RISCV/vsetvli.s
Index: llvm/test/tools/llvm-objdump/RISCV/vsetvli.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/RISCV/vsetvli.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t
+# RUN: llvm-objdump -D --mattr=+experimental-v %t | FileCheck %s
+
+# CHECK: vsetvli a1, a0, e64, m1, tu, mu
+# CHECK-NEXT: vsetvli a1, a0, e64, <reserved LMUL>, tu, mu
+# CHECK-NEXT: vsetvli a1, a0, e64, mf8, tu, mu
+
+.data
+.word 0x018575d7
+.word 0x01c575d7
+.word 0x01d575d7
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -409,6 +409,7 @@
unsigned LMulVal;
bool Fractional;
std::tie(LMulVal, Fractional) = RISCVVType::decodeVLMUL(LMul);
+ assert(LMulVal != 0 && "Reserved LMUL value");
assert(!Fractional && "It is impossible be fractional lmul here.");
if (forwardCopyWillClobberTuple(DstEncoding, SrcEncoding, NF * LMulVal)) {
I = NF - 1;
Index: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -155,6 +155,7 @@
unsigned LMul;
bool Fractional;
std::tie(LMul, Fractional) = RISCVVType::decodeVLMUL(VLMul);
+ assert(LMul != 0 && "Reserved LMUL value");
// Convert LMul to a fixed point value with 3 fractional bits.
LMul = Fractional ? (8 / LMul) : (LMul * 8);
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
@@ -138,7 +138,7 @@
std::pair<unsigned, bool> RISCVVType::decodeVLMUL(RISCVII::VLMUL VLMUL) {
switch (VLMUL) {
default:
- llvm_unreachable("Unexpected LMUL value!");
+ return std::make_pair(0, false);
case RISCVII::VLMUL::LMUL_1:
case RISCVII::VLMUL::LMUL_2:
case RISCVII::VLMUL::LMUL_4:
@@ -159,11 +159,12 @@
bool Fractional;
std::tie(LMul, Fractional) = decodeVLMUL(getVLMUL(VType));
- if (Fractional)
- OS << ", mf";
+ if (LMul == 0)
+ OS << ", <reserved LMUL>";
+ else if (Fractional)
+ OS << ", mf" << LMul;
else
- OS << ", m";
- OS << LMul;
+ OS << ", m" << LMul;
if (isTailAgnostic(VType))
OS << ", ta";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114581.389795.patch
Type: text/x-patch
Size: 2548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211125/3b34306c/attachment.bin>
More information about the llvm-commits
mailing list