[PATCH] D70246: [InstCombine] remove identity shuffle simplification for mask with undefs

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 08:25:30 PST 2019


spatel created this revision.
spatel added reviewers: efriedma, regehr, aqjune, nlopes, RKSimon, lebedev.ri, liuz.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.

Given a shuffle that includes undef elements in an otherwise identity mask like:

  define <4 x float> @shuffle(<4 x float> %arg) {
    %shuf = shufflevector <4 x float> %arg, <4 x float> undef, <4 x i32> <i32 undef, i32 1, i32 2, i32 3>
    ret <4 x float> %shuf
  }

We were simplifying that to the input operand.

But as discussed in PR43958:
https://bugs.llvm.org/show_bug.cgi?id=43958
...that means that per-vector-element poison that would be stopped by the shuffle can now leak to the result.

For reference, this transform was added long ago with:
rL142671 <https://reviews.llvm.org/rL142671>

Also note that we still have (and there are tests for) the same transform with no undef elements in the mask (a fully-defined identity mask). I don't think there's any controversy about that case - it's a valid transform under any interpretation of shufflevector/undef/poison.

Looking at a few of the diffs into codegen, I don't see any difference in final asm. So depending on your perspective, that's good (no real loss of optimization power) or bad (poison exists in the DAG, so we only partially fixed the bug).


https://reviews.llvm.org/D70246

Files:
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/X86/clmulqdq.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx2.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
  llvm/test/Transforms/InstCombine/X86/x86-pack.ll
  llvm/test/Transforms/InstCombine/X86/x86-pshufb.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse41.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
  llvm/test/Transforms/InstCombine/X86/x86-vector-shifts.ll
  llvm/test/Transforms/InstCombine/X86/x86-vpermil.ll
  llvm/test/Transforms/InstCombine/X86/x86-xop.ll
  llvm/test/Transforms/InstCombine/shuffle_select.ll
  llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
  llvm/test/Transforms/InstCombine/vec_shuffle.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70246.229312.patch
Type: text/x-patch
Size: 75682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191114/72f543ef/attachment.bin>


More information about the llvm-commits mailing list