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

[SLPVectorizer] Miscompile at O3 #105988

Closed
dtcxzyw opened this issue Aug 25, 2024 · 1 comment
Closed

[SLPVectorizer] Miscompile at O3 #105988

dtcxzyw opened this issue Aug 25, 2024 · 1 comment

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 25, 2024

Reproducer: https://gist.github.com/dtcxzyw/117dc735db97658ea852d30fd896242a

> bin/clang -O0 test.c -w -I/usr/include/csmith && ./a.out
checksum = BDCB7A78
> bin/clang -O3 test.c -w -mllvm -inline-threshold=100000 -I/usr/include/csmith && ./a.out
checksum = 9198FC41

llvm version: 1193f7d

@dtcxzyw dtcxzyw added miscompilation llvm:optimizations needs-reduction Large reproducer that should be reduced into a simpler form labels Aug 25, 2024
@dtcxzyw dtcxzyw self-assigned this Aug 25, 2024
@dtcxzyw
Copy link
Member Author

dtcxzyw commented Aug 25, 2024

Reproducer: https://alive2.llvm.org/ce/z/GCXoe9

; bin/opt -passes=slp-vectorizer test.ll -S

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i1 @main(i32 %g.promoted.i.i, i16 %d.promoted.i.i) {
entry:
  %0 = and i16 %d.promoted.i.i, 1
  %xor.i.i = xor i32 %g.promoted.i.i, 1
  %conv1.i.i = trunc i32 %xor.i.i to i8
  %notsub.i = add i8 %conv1.i.i, -1
  %cmp.i.i = icmp sgt i8 %notsub.i, -3
  %conv3.i.i = zext i1 %cmp.i.i to i32
  %cmp4.i.i = icmp sgt i32 %xor.i.i, %conv3.i.i
  %conv1.1.i.i = trunc i32 %g.promoted.i.i to i8
  %notsub25.i = add i8 %conv1.1.i.i, -1
  %cmp.1.i.i = icmp sgt i8 %notsub25.i, -3
  %conv3.1.i.i = zext i1 %cmp.1.i.i to i32
  %cmp4.1.i.i = icmp sgt i32 %g.promoted.i.i, %conv3.1.i.i
  %notsub26.i = add i8 %conv1.1.i.i, -9
  %cmp.i17.i = icmp sgt i8 %notsub26.i, -3
  %conv3.i18.i = zext i1 %cmp.i17.i to i32
  %cmp4.i19.i = icmp sgt i32 %g.promoted.i.i, %conv3.i18.i
  %notsub27.i = add i8 %conv1.i.i, -9
  %cmp.1.i22.i = icmp sgt i8 %notsub27.i, -3
  %conv3.1.i23.i = zext i1 %cmp.1.i22.i to i32
  %cmp4.1.i24.i = icmp sgt i32 %xor.i.i, %conv3.1.i23.i
  %1 = and i1 %cmp4.i19.i, %cmp4.1.i24.i
  %2 = and i1 %cmp4.i.i, %1
  %3 = and i1 %cmp4.1.i.i, %2
  ret i1 %3
}

Output:

define i1 @main(i32 %g.promoted.i.i, i16 %d.promoted.i.i) {
entry:
  %0 = and i16 %d.promoted.i.i, 1
  %xor.i.i = xor i32 %g.promoted.i.i, 1
  %1 = trunc i32 %g.promoted.i.i to i8
  %2 = insertelement <2 x i8> poison, i8 %1, i32 0
  %3 = trunc i32 %xor.i.i to i8
  %4 = insertelement <2 x i8> %2, i8 %3, i32 1
  %5 = shufflevector <2 x i8> %4, <2 x i8> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %6 = add <4 x i8> %5, <i8 -9, i8 -9, i8 -1, i8 -1>
  %7 = icmp sgt <4 x i8> %6, <i8 -3, i8 -3, i8 -3, i8 -3>
  %8 = zext <4 x i1> %7 to <4 x i8>
  %9 = sext <2 x i8> %4 to <2 x i32>
  %10 = shufflevector <2 x i32> %9, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
  %11 = zext <4 x i8> %8 to <4 x i32>
  %12 = icmp sgt <4 x i32> %10, %11
  %13 = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %12)
  ret i1 %13
}

cc @alexey-bataev

@dtcxzyw dtcxzyw removed their assignment Aug 25, 2024
@dtcxzyw dtcxzyw removed the needs-reduction Large reproducer that should be reduced into a simpler form label Aug 25, 2024
@dtcxzyw dtcxzyw changed the title [LLVM] Miscompile at O3 [SLPVectorizer] Miscompile at O3 Aug 25, 2024
@alexey-bataev alexey-bataev self-assigned this Aug 26, 2024
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this issue Aug 29, 2024
If the node is not in MinBWs container and the user node is icmp node,
the compiler should not check the type size of the user instruction, it
is always 1 and is not good for actual bitwidth analysis.

Fixes llvm#105988
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this issue Sep 2, 2024
If the node is not in MinBWs container and the user node is icmp node,
the compiler should not check the type size of the user instruction, it
is always 1 and is not good for actual bitwidth analysis.

Fixes llvm#105988
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

3 participants