Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLP vectorizer's reduce_and formation introduces poison #55734

Open
nunoplopes opened this issue May 27, 2022 · 0 comments
Open

SLP vectorizer's reduce_and formation introduces poison #55734

nunoplopes opened this issue May 27, 2022 · 0 comments

Comments

@nunoplopes
Copy link
Member

nunoplopes commented May 27, 2022

Reduced test case from SLPVectorizer/X86/reduction-logical.ll's logical_and_icmp_clamp_extra_use_select:

define i1 @src(i32 %x3, i1 %d2) {
  %c2 = icmp slt i32 0, 0
  %c3 = icmp slt i32 %x3, 0
  %d0 = icmp sgt i32 1, 0
  %d1 = icmp sgt i32 1, 0
  %d22 = icmp sgt i32 1, 0
  %d3 = icmp sgt i32 1, 0
  %s2 = select i1 false, i1 false, i1 false
  %s3 = select i1 %s2, i1 %c3, i1 false
  %s4 = select i1 %s3, i1 %d0, i1 false
  %s5 = select i1 %s4, i1 %d1, i1 false
  %s6 = select i1 %s5, i1 %d2, i1 false
  %s7 = select i1 %s6, i1 %d3, i1 false
  ret i1 %s7
}

Alive2's output, showing that the SLP vectorizer changes the return value to poison because it flips the order of selects:

define i1 @src(i32 %x3, i1 %d2) {
%0:
  %c2 = icmp slt i32 0, 0
  %c3 = icmp slt i32 %x3, 0
  %d0 = icmp sgt i32 1, 0
  %d1 = icmp sgt i32 1, 0
  %d22 = icmp sgt i32 1, 0
  %d3 = icmp sgt i32 1, 0
  %s2 = select i1 0, i1 0, i1 0
  %s3 = select i1 %s2, i1 %c3, i1 0
  %s4 = select i1 %s3, i1 %d0, i1 0
  %s5 = select i1 %s4, i1 %d1, i1 0
  %s6 = select i1 %s5, i1 %d2, i1 0
  %s7 = select i1 %s6, i1 %d3, i1 0
  ret i1 %s7
}
=>
define i1 @src(i32 %x3, i1 %d2) {
%0:
  %c2 = icmp slt i32 0, 0
  %1 = insertelement <4 x i32> { 0, 0, 0, poison }, i32 %x3, i32 3
  %2 = icmp sgt <4 x i32> { 1, 1, 1, 0 }, %1
  %d22 = icmp sgt i32 1, 0
  %s2 = select i1 0, i1 0, i1 0
  %3 = freeze <4 x i1> %2
  %4 = reduce_and <4 x i1> %3
  %op.rdx = select i1 %d2, i1 %s2, i1 0
  %op.rdx1 = select i1 %4, i1 %op.rdx, i1 0
  ret i1 %op.rdx1
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source

Example:
i32 %x3 = poison
i1 %d2 = poison

Source:
i1 %c2 = #x0 (0)
i1 %c3 = poison
i1 %d0 = #x1 (1)
i1 %d1 = #x1 (1)
i1 %d22 = #x1 (1)
i1 %d3 = #x1 (1)
i1 %s2 = #x0 (0)
i1 %s3 = #x0 (0)
i1 %s4 = #x0 (0)
i1 %s5 = #x0 (0)
i1 %s6 = #x0 (0)
i1 %s7 = #x0 (0)

Target:
i1 %c2 = #x0 (0)
<4 x i32> %1 = < #x00000000 (0), #x00000000 (0), #x00000000 (0), poison >
<4 x i1> %2 = < #x1 (1), #x1 (1), #x1 (1), poison >
i1 %d22 = #x1 (1)
i1 %s2 = #x0 (0)
<4 x i1> %3 = < #x1 (1), #x1 (1), #x1 (1), #x1 (1) >
i1 %4 = #x1 (1)
i1 %op.rdx = poison
i1 %op.rdx1 = poison
Source value: #x0 (0)
Target value: poison

cc @regehr @alexey-bataev @cilkplus @davemgreen @RKSimon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant