[PATCH] D93818: [LangRef] Update shufflevector's semantics to return poison if the mask is undef

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 25 15:30:46 PST 2020


aqjune created this revision.
aqjune added reviewers: spatel, efriedma, jdoerfert, nikic, lebedev.ri, nlopes, regehr.
Herald added a subscriber: pengfei.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch updates shufflevector's semantics to return poison if the mask is undef.
It resolves shufflevector-related bugs which is described at https://reviews.llvm.org/D93586.

This resolves many bugs that are marked as 'LLVM PR44185' at https://web.ist.utl.pt/nuno.lopes/alive2/index.php?hash=3c479a0f6691091c .

*But*, it also makes a few transformations invalid:

Transforms/InstCombine/broadcast.ll: https://bugs.llvm.org/show_bug.cgi?id=43958
Transforms/VectorCombine/X86/load.ll: a transformation that's similar to the previous one
Transforms/InstCombine/sub-of-negatible.ll:

  define <2 x i4> @negate_shufflevector_oneinput_second_lane_is_undef(<2 x i4> %x, <2 x i4> %y) {
  %0:
    %t0 = shl <2 x i4> { 10, 5 }, %x
    ; t1[2] is undef, not poison
    %t1 = shufflevector <2 x i4> %t0, <2 x i4> undef, 0, 2  
    %t2 = sub <2 x i4> %y, %t1
    ret <2 x i4> %t2
  }
  =>
  define <2 x i4> @negate_shufflevector_oneinput_second_lane_is_undef(<2 x i4> %x, <2 x i4> %y) {
  %0:
    %t0.neg = shl <2 x i4> { 6, 11 }, %x
    ; t1[2] is poison
    %t1.neg = shufflevector <2 x i4> %t0.neg, <2 x i4> undef, 0, 4294967295 
    %t2 = add <2 x i4> %t1.neg, %y
    ret <2 x i4> %t2
  }
  Transformation doesn't verify!
  ERROR: Target is more poisonous than source

Transforms/InstCombine/insert-const-shuf.ll:

  define <5 x i8> @longerMask(<3 x i8> %x) {
  %0:
    ; %shuf[3] = undef
    %shuf = shufflevector <3 x i8> %x, <3 x i8> { undef, 1, 2 }, 2, 1, 4, 3, 0
    %ins = insertelement <5 x i8> %shuf, i8 42, i17 4
    ret <5 x i8> %ins
  }
  =>
  define <5 x i8> @longerMask(<3 x i8> %x) {
  %0:
    ; %shuf[3] = poison
    %shuf = shufflevector <3 x i8> %x, <3 x i8> { poison, 1, poison }, 2, 1, 4, 4294967295, 4294967295
    %ins = insertelement <5 x i8> %shuf, i8 42, i17 4
    ret <5 x i8> %ins
  }
  Transformation doesn't verify!
  ERROR: Target is more poisonous than source

I think these transformations are all solvable: we can simply disable these transformations if insertelement/shufflevector's placeholder isn't poison.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93818

Files:
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -9085,12 +9085,10 @@
 to the result. Non-negative elements in the mask represent an index
 into the concatenated pair of input vectors.
 
-If the shuffle mask is undefined, the result vector is undefined. If
+If the shuffle mask is undefined, the result vector is poison. If
 the shuffle mask selects an undefined element from one of the input
 vectors, the resulting element is undefined. An undefined element
-in the mask vector specifies that the resulting element is undefined.
-An undefined element in the mask vector prevents a poisoned vector
-element from propagating.
+in the mask vector specifies that the resulting element is poison.
 
 For scalable vectors, the only valid mask values at present are
 ``zeroinitializer`` and ``undef``, since we cannot write all indices as


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93818.313737.patch
Type: text/x-patch
Size: 937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201225/1218478e/attachment.bin>


More information about the llvm-commits mailing list