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] SLP Vectorizer miscompile from reducing abs bitwidth #112577

Closed
danilaml opened this issue Oct 16, 2024 · 5 comments
Closed

[SLP] SLP Vectorizer miscompile from reducing abs bitwidth #112577

danilaml opened this issue Oct 16, 2024 · 5 comments

Comments

@danilaml
Copy link
Collaborator

Bisected miscompile to this change 4a1c53f

Reduced internal test to this example:
https://godbolt.org/z/njWYP9exd

define dso_local noundef i32 @test(i32 %n) local_unnamed_addr #0 {
entry:
  %n1 = add i32 %n, 1
  %zn1 = zext nneg i32 %n1 to i64
  %m1 = mul nuw nsw i64 %zn1, 273837369
  %a1 = call noundef i64 @llvm.abs.i64(i64 %m1, i1 true)
  %t1 = trunc i64 %a1 to i32
  %n2 = add i32 %n, 2
  %zn2 = zext nneg i32 %n2 to i64
  %m2 = mul nuw nsw i64 %zn2, 273837369
  %a2 = call noundef i64 @llvm.abs.i64(i64 %m2, i1 true)
  %t2 = trunc i64 %a2 to i32

  %res1 = add i32 %t1, %t2
  ret i32 %res1
}

Running slp vectorizer on it gives

define dso_local noundef i32 @test(i32 %n) local_unnamed_addr {
  %0 = insertelement <2 x i32> poison, i32 %n, i32 0
  %1 = shufflevector <2 x i32> %0, <2 x i32> poison, <2 x i32> zeroinitializer
  %2 = add <2 x i32> %1, <i32 1, i32 2>
  %3 = mul <2 x i32> %2, <i32 273837369, i32 273837369>
  %4 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %3, i1 false)
  %5 = extractelement <2 x i32> %4, i32 0
  %6 = extractelement <2 x i32> %4, i32 1
  %res1 = add i32 %5, %6
  ret i32 %res1
}

which is incorrect. Counterexample by alive2:
https://alive2.llvm.org/ce/z/cEcY-u

@AZero13
Copy link
Contributor

AZero13 commented Oct 19, 2024

Do we plan on backporting this to 19.x @alexey-bataev

@alexey-bataev
Copy link
Member

/cherry-pick 709abac

@llvmbot
Copy link
Member

llvmbot commented Oct 19, 2024

Failed to cherry-pick: 709abac

https://github.com/llvm/llvm-project/actions/runs/11419324038

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@alexey-bataev
Copy link
Member

/cherry-pick 825f9cb 709abac

@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2024

/pull-request #113146

EricWF pushed a commit to efcs/llvm-project that referenced this issue Oct 22, 2024
…t of minbitwidth transformation

Need to check that the operand of the abs intrinsic can be safely
truncated before making it part of the minbitwidth transformation.

Fixes llvm#112577
@tru tru moved this from Needs Triage to Done in LLVM Release Status Oct 28, 2024
tru pushed a commit to llvmbot/llvm-project that referenced this issue Dec 2, 2024
…t of minbitwidth transformation

Need to check that the operand of the abs intrinsic can be safely
truncated before making it part of the minbitwidth transformation.

Fixes llvm#112577

(cherry picked from commit 709abac)
jabraham17 added a commit to chapel-lang/chapel that referenced this issue Dec 3, 2024
Backports a fix for llvm/llvm-project#112577
and llvm/llvm-project#118410 to the bundled
version of LLVM in our source tree.

Resolves #26301

- [x] Tested that the bitwidth bug is resolved with the bundled LLVM on
M1 Mac
- [x] full paratest with/without gasnet

[Reviewed by @mppf]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

5 participants