Issue 237543
Summary [VectorCombine] Narrowing a phi of shuffles turns defined lanes into poison when a mask selects the second operand
Labels miscompilation, generated by fuzzer, llvm:vectorcombine
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/E7cPn6h6s
alive: https://alive2.llvm.org/ce/z/9PhH_P

```llvm
target triple = "x86_64-unknown-linux-gnu"

define <2 x i32> @f(i1 %c, <1 x i32> %v) {
entry:
  br i1 %c, label %a, label %b

a:
  %s0 = shufflevector <1 x i32> %v, <1 x i32> poison, <2 x i32> zeroinitializer
  br label %join

b:
  %s1 = shufflevector <1 x i32> %v, <1 x i32> poison, <2 x i32> <i32 1, i32 1>
  br label %join

join:
  %p = phi <2 x i32> [ %s0, %a ], [ %s1, %b ]
  ret <2 x i32> %p
}

define i32 @main() {
  %v = call <2 x i32> @f(i1 true, <1 x i32> <i32 3>)
  %r = extractelement <2 x i32> %v, i64 0
  %failed = icmp ne i32 %r, 3
  %exit_code = zext i1 %failed to i32
 ret i32 %exit_code
}
```

```console
$ opt -S -passes=vector-combine issue-repro.ll
...
define <2 x i32> @f(i1 %c, <1 x i32> %v) {
entry:
  br i1 %c, label %a, label %b

a: ; preds = %entry
  br label %join

b: ; preds = %entry
  br label %join

join: ; preds = %b, %a
  ret <2 x i32> poison
}
...

$ alive-tv --disable-undef-input --disable-poison-input -passes=vector-combine issue-repro.ll
...
Transformation doesn't verify!

ERROR: Target is more poisonous than source

NOTE: The counterexample is unique.

Example:
i1 %c = #x1 (1)
<1 x i32> %v = < #x00000003 (3) >

Source:
  >> Jump to %a
<2 x i32> %s0 = < #x00000003 (3), #x00000003 (3) >
  >> Jump to %join
<2 x i32> %p = < #x00000003 (3), #x00000003 (3) >

Target:
  >> Jump to %a
<1 x i32> %#0 = < #x00000003 (3) >
  >> Jump to %join
<1 x i32> %#1 = < #x00000003 (3) >
<2 x i32> %p = < poison, poison >
Source value: < #x00000003 (3), #x00000003 (3) >
Target value: < poison, poison >
...
Summary:
  1 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```

### suggested fix
`VectorCombine::shrinkPhiOfShuffles` should classify mask indices `>= InputNumElements` as poison, just like `-1`, before computing `M0 - M1`.
Skip pairs that select poison on both sides and reject pairs where only one side selects poison.
This prevents the final shuffle with `Mask1` from replacing defined lanes on the first incoming edge with poison.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to