[PATCH] D80330: [BitcodeReader] Fix DelayedShuffle handling for ConstantExpr shuffles.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 20 15:27:36 PDT 2020
efriedma created this revision.
efriedma added reviewers: mehdi_amini, jdoerfert, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
The indexing was messed up, so the result was completely broken.
Shuffle constant exprs are rare in practice; without vscale types, constant folding generally elminates them. So sort of hard to trip over.
Fixes regression from D72467 <https://reviews.llvm.org/D72467>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80330
Files:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Bitcode/vscale-shuffle.ll
Index: llvm/test/Bitcode/vscale-shuffle.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/vscale-shuffle.ll
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llvm-dis -disable-output
+; RUN: verify-uselistorder < %s
+
+define void @f() {
+ %l = call <vscale x 16 x i8> @l(<vscale x 16 x i1> shufflevector (<vscale x 16 x i1> insertelement (<vscale x 16 x i1> undef, i1 true, i32 0), <vscale x 16 x i1> undef, <vscale x 16 x i32> zeroinitializer))
+ %i = add <vscale x 2 x i64> undef, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 1, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer)
+ unreachable
+}
+
+declare <vscale x 16 x i8> @l(<vscale x 16 x i1>)
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2338,6 +2338,7 @@
uint64_t Op0Idx;
uint64_t Op1Idx;
uint64_t Op2Idx;
+ unsigned CstNo;
};
std::vector<DelayedShufTy> DelayedShuffles;
while (true) {
@@ -2351,9 +2352,6 @@
case BitstreamEntry::Error:
return error("Malformed block");
case BitstreamEntry::EndBlock:
- if (NextCstNo != ValueList.size())
- return error("Invalid constant reference");
-
// Once all the constants have been read, go through and resolve forward
// references.
//
@@ -2366,6 +2364,7 @@
uint64_t Op0Idx = DelayedShuffle.Op0Idx;
uint64_t Op1Idx = DelayedShuffle.Op1Idx;
uint64_t Op2Idx = DelayedShuffle.Op2Idx;
+ uint64_t CstNo = DelayedShuffle.CstNo;
Constant *Op0 = ValueList.getConstantFwdRef(Op0Idx, OpTy);
Constant *Op1 = ValueList.getConstantFwdRef(Op1Idx, OpTy);
Type *ShufTy =
@@ -2376,9 +2375,12 @@
SmallVector<int, 16> Mask;
ShuffleVectorInst::getShuffleMask(Op2, Mask);
Value *V = ConstantExpr::getShuffleVector(Op0, Op1, Mask);
- ValueList.assignValue(V, NextCstNo, DelayedShuffle.CurFullTy);
- ++NextCstNo;
+ ValueList.assignValue(V, CstNo, DelayedShuffle.CurFullTy);
}
+
+ if (NextCstNo != ValueList.size())
+ return error("Invalid constant reference");
+
ValueList.resolveConstantForwardRefs();
return Error::success();
case BitstreamEntry::Record:
@@ -2734,7 +2736,8 @@
if (Record.size() < 3 || !OpTy)
return error("Invalid record");
DelayedShuffles.push_back(
- {OpTy, OpTy, CurFullTy, Record[0], Record[1], Record[2]});
+ {OpTy, OpTy, CurFullTy, Record[0], Record[1], Record[2], NextCstNo});
+ ++NextCstNo;
continue;
}
case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval]
@@ -2744,7 +2747,8 @@
if (Record.size() < 4 || !RTy || !OpTy)
return error("Invalid record");
DelayedShuffles.push_back(
- {OpTy, RTy, CurFullTy, Record[1], Record[2], Record[3]});
+ {OpTy, RTy, CurFullTy, Record[1], Record[2], Record[3], NextCstNo});
+ ++NextCstNo;
continue;
}
case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80330.265359.patch
Type: text/x-patch
Size: 3248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200520/fe611681/attachment.bin>
More information about the llvm-commits
mailing list