This patch updates the remaining transformations to create insertelement/shufflevector with poison placeholder.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Alive2 result: Running Alive2 finds one failure, which is fixed by updating the shufflevector semantics to return poison on undef/poison mask (D93818):
Transforms/InstCombine/shufflevector-div-rem-inseltpoison.ll ---------------------------------------- define <2 x float> @test_fdiv(float %a, float %b, i1 %cmp) { %0: %splatinsert = insertelement <2 x float> poison, float %a, i32 0 %denom = insertelement <2 x float> { 3.000000, poison }, float 1.000000, i32 1 %t1 = fdiv <2 x float> %splatinsert, %denom %splat.op = shufflevector <2 x float> %t1, <2 x float> poison, 4294967295, 0 ; THIS BLOCKS POISON %t2 = select i1 %cmp, <2 x float> { 77.000000, 99.000000 }, <2 x float> %splat.op ret <2 x float> %t2 } => define <2 x float> @test_fdiv(float %a, float %b, i1 %cmp) { %0: %1 = insertelement <2 x float> poison, float %a, i32 1 %2 = fdiv <2 x float> %1, { undef, 3.000000 } %t2 = select i1 %cmp, <2 x float> { 77.000000, 99.000000 }, <2 x float> %2 ret <2 x float> %t2 } Transformation doesn't verify! ERROR: Target is more poisonous than source
Diffs in llvm/test and clang/test: I checked that all of these are replacements of undef with poison, and there was no larger change.
Remaining undef placeholder: After this patch, there are two places where undef still shows up as a placeholder from llvm tests: I couldn't find where they are coming from. :(
If someone points me where they're likely to appear, I'll fix these.
$ ag "shufflevector <.*> .*, <.*> undef" | grep inseltpoison Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll $ ag "insertelement <.*> undef" | grep inseltpoison Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts-inseltpoison.ll
I'll split this patch into smaller pieces, so they're able to get reviewed more easily.
Factored out non-instcombine diffs; I'll split the instcombine diffs into several patches too
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
1221 ↗ | (On Diff #315691) | This change is okay because it is splat (only the first vector of shufflevector was accessed) |
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp | ||
551 | ||
594 | Okay to be poison (the added comment above replaceExtractElements has details) | |
1122 | Since this is creating a splat, this shufflevector change and the insertelement change above is okay. | |
1333 | Values is the RHS of a new shufflevector below. | |
1430 | When LR.second was nullptr, it was simply a placeholder (so okay to be poison) | |
2344 | As seen in line 2353, Elts' indices are smaller than LHSWidth, so okay to be poison. |
clang-format not found in user's PATH; not linting file.