diff options
author | Philip Reames <listmail@philipreames.com> | 2019-01-24 16:08:18 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-01-24 16:08:18 +0000 |
commit | a657510eb7492896589c97065e2ef3c770742a78 (patch) | |
tree | 57f199cee86f978cab12624c7de018ccbe364264 /llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | |
parent | f7098b3a041eaa8e6af607cc298036924ec512ee (diff) | |
download | bcm5719-llvm-a657510eb7492896589c97065e2ef3c770742a78.tar.gz bcm5719-llvm-a657510eb7492896589c97065e2ef3c770742a78.zip |
[RS4GC] Avoid crashing on gep scalar_base, vector_idx
This is an alternative to https://reviews.llvm.org/D57103. After discussion, we dedicided to check this in as a temporary workaround, and pursue a true fix under the original thread.
The issue at hand is that the base rewriting algorithm doesn't consider the fact that GEPs can turn a scalar input into a vector of outputs. We had handling for scalar GEPs and fully vector GEPs (i.e. all vector operands), but not the scalar-base + vector-index forms. A true fix here requires treating GEP analogously to extractelement or shufflevector.
This patch is merely a workaround. It simply hides the crash at the cost of some ugly code gen for this presumable very rare pattern.
Differential Revision: https://reviews.llvm.org/D57138
llvm-svn: 352059
Diffstat (limited to 'llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index 81dd4b5172c..e722456b1e6 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -2601,6 +2601,34 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT, } } + // Nasty workaround - The base computation code in the main algorithm doesn't + // consider the fact that a GEP can be used to convert a scalar to a vector. + // The right fix for this is to integrate GEPs into the base rewriting + // algorithm properly, this is just a short term workaround to prevent + // crashes by canonicalizing such GEPs into fully vector GEPs. + for (Instruction &I : instructions(F)) { + if (!isa<GetElementPtrInst>(I)) + continue; + + unsigned VF = 0; + bool HasScalarOperand = false; + for (unsigned i = 0; i < I.getNumOperands(); i++) + if (I.getOperand(i)->getType()->isVectorTy()) + VF = I.getOperand(i)->getType()->getVectorNumElements(); + else + HasScalarOperand = true; + + if (HasScalarOperand && VF != 0) { + IRBuilder<> B(&I); + for (unsigned i = 0; i < I.getNumOperands(); i++) + if (!I.getOperand(i)->getType()->isVectorTy()) { + auto *Splat = B.CreateVectorSplat(VF, I.getOperand(i)); + I.setOperand(i, Splat); + MadeChange = true; + } + } + } + MadeChange |= insertParsePoints(F, DT, TTI, ParsePointNeeded); return MadeChange; } |