llvm-project/llvm/test/Transforms/PhaseOrdering
Juneyoung Lee 9d70dbdc2b [InstCombine] use poison as placeholder for undemanded elems
Currently undef is used as a don’t-care vector when constructing a vector using a series of insertelement.
However, this is problematic because undef isn’t undefined enough.
Especially, a sequence of insertelement can be optimized to shufflevector, but using undef as its placeholder makes shufflevector a poison-blocking instruction because undef cannot be optimized to poison.
This makes a few straightforward optimizations incorrect, such as:

```
;  https://bugs.llvm.org/show_bug.cgi?id=44185

define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) {
  %xv = insertelement <4 x float> %q, float %x, i32 2
  %r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> { 0, 6, 2, undef }
  ret <4 x float> %r ; %r[3] is undef
}
=>
define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) {
  %r = insertelement <4 x float> %y, float %x, i32 1
  ret <4 x float> %r ; %r[3] = %y[3], incorrect if %y[3] = poison
}

Transformation doesn't verify!
ERROR: Target is more poisonous than source
```

I’d like to suggest
1. Using poison as insertelement’s placeholder value (IRBuilder::CreateVectorSplat should be patched too)
2. Updating shufflevector’s semantics to return poison element if mask is undef

Note that poison is currently lowered into UNDEF in SelDag, so codegen part is okay.
m_Undef() matches PoisonValue as well, so existing optimizations will still fire.

The only concern is hidden miscompilations that will go incorrect when poison constant is given.
A conservative way is copying all tests having `insertelement undef` & replacing it with `insertelement poison` & run Alive2 on it, but it will create many tests and people won’t like it. :(

Instead, I’ll simply locally maintain the tests and run Alive2.
If there is any bug found, I’ll report it.

Relevant links: https://bugs.llvm.org/show_bug.cgi?id=43958 , http://lists.llvm.org/pipermail/llvm-dev/2019-November/137242.html

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D93586
2020-12-28 08:58:15 +09:00
..
ARM [FileCheck] Enforce --allow-unused-prefixes=false for llvm/test/Transforms 2020-12-09 08:51:38 -08:00
X86 [InstCombine] use poison as placeholder for undemanded elems 2020-12-28 08:58:15 +09:00
2010-03-22-empty-baseclass.ll
PR6627.ll
basic.ll [NFC][PhaseOrdering] Autogenerate basic.ll test 2020-10-27 14:42:53 +03:00
bitfield-bittests.ll
d83507-knowledge-retention-bug.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
gdce.ll
globalaa-retained.ll [test] Fix globalaa-retained.ll under NPM 2020-11-19 14:24:46 -08:00
inlining-alignment-assumptions.ll OpaquePtr: Bulk update tests to use typed sret 2020-11-20 17:58:26 -05:00
instcombine-sroa-inttoptr.ll OpaquePtr: Bulk update tests to use typed sret 2020-11-20 17:58:26 -05:00
lifetime-sanitizer.ll
loop-rotation-vs-common-code-hoisting.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
min-max-abs-cse.ll [InstCombine] Canonicalize SPF to abs intrinsic 2020-12-18 21:18:14 +03:00
minmax.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
pr39282.ll [test] Fix pr39282.ll under NPM 2020-11-19 14:19:48 -08:00
reassociate-after-unroll.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
rotate.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
scev-custom-dl.ll [NPM] Fix some PhaseOrdering tests under NPM 2020-10-16 16:58:14 -07:00
scev.ll [NPM] Fix some PhaseOrdering tests under NPM 2020-10-16 16:58:14 -07:00
simplifycfg-options.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
two-shifts-by-sext.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00
unsigned-multiply-overflow-check.ll [SimplifyCFG] Teach FoldTwoEntryPHINode() to preserve DomTree 2020-12-20 00:18:33 +03:00
vector-trunc-inseltpoison.ll Precommit transform tests that have poison as insertelement's placeholder 2020-12-24 11:46:17 +09:00
vector-trunc.ll [PhaseOrdering] Remove unused check-prefixes 2020-11-08 13:30:18 +00:00