Seg fault during NEON compilation with short3/4 division
| Bugzilla Link | 10897 |
| Resolution | FIXED |
| Resolved on | Sep 09, 2011 16:04 |
| Version | trunk |
| OS | Linux |
| Attachments | Failing bitcode file |
| CC | @efriedma-quic,@jmolloy,@sunfishcode,@stephenhines |
Extended Description
Running llc targeting ARMv7 with NEON on the attached bitcode file results in seg fault (and assertion failure if those are enabled). Note that this is a reduced test case. I could not get the bug to manifest when I stopped doing divides of both short3 and short4 types.
llc: /srhines-dt/srhines/tot_llvm/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h:190: llvm::SDValue llvm::DAGTypeLegalizer::GetPromotedInteger(llvm::SDValue): Assertion `PromotedOp.getNode() && "Operand wasn't promoted?"' failed. 0 llc 0x08a84e58 Stack dump: 0. Program arguments: /srhines-dt/srhines/tot_llvm/llvm-bin/bin/llc tmp_srhines/fail.bc
- Running pass 'Function Pass Manager' on module 'tmp_srhines/fail.bc'.
- Running pass 'ARM Instruction Selection' on function '@math_test' Aborted
r139407.
Proposed fix Hi,
The attached patch fixes bug 10897.
The issue was in the DAGCombiner, when constant-folding "insert_vector_emt" nodes on a vector that had been size-extended (<3 x int> -> <4 x int> for example).
The DAGCombiner was inserting UNDEFs for all values in the vector, and the folded insert_vector_emt nodes replace those UNDEFs with actual content. But the padding at the end, in the case where the original vector was not a power of 2, isn't changed.
This is fine, apart from the type that was being used for UNDEF was the type of the vector element, which may not be legal. As DAGTypeLegalizer has already run by this point, inserting illegal nodes causes assertion failures later down the line.
The fix is to ensure the type of the UNDEFs are legal types:
- if (!isTypeLegal(EltVT))
-
EltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT); - assert(isTypeLegal(EltVT) && "Vector element type was not legal!");
Aside: The documentation for TargetLowering::getTypeToTransformTo() states that if the input parameter is legal, the function is equivalent to the identity function. I should therefore not need the "isTypeLegal" check on the line above.
Changing this however broke a lot of codegen tests, both in the ARM and X86 backends. Does anyone know why that might be the case? For the X86 test I looked at, getTypeToTransformTo appeared to be changing an i64 to a v2i64 (IIRC).
Patch attached, testcase added. OK to commit?
Cheers,
James
This is exploding in PromoteIntOp_BUILD_VECTOR because it implicitly assumes all the operands of BUILD_VECTOR have the same type. DAGCombiner::visitINSERT_VECTOR_ELT generates a BUILD_VECTOR which does not match that assumption. Not sure what the best fix is here.
assigned to @jmolloy