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 produces use-before-def after 03b118c #70004

Closed
dyung opened this issue Oct 24, 2023 · 7 comments · Fixed by llvm/llvm-project-release-prs#764
Closed

SLPVectorizer produces use-before-def after 03b118c #70004

dyung opened this issue Oct 24, 2023 · 7 comments · Fixed by llvm/llvm-project-release-prs#764

Comments

@dyung
Copy link
Collaborator

dyung commented Oct 24, 2023

While doing some work internally, we encountered a test case where the SLP Vectorizer pass was creating a use-before-def which we bisected back to change 03b118c.

Consider the following code:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-sie-ps5"

define void @_Z3fooP3bar() {
.thread:
  %0 = extractelement <2 x i1> zeroinitializer, i64 0
  %1 = extractelement <2 x i1> zeroinitializer, i64 0
  %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  %3 = extractelement <2 x i1> %2, i64 0
  %4 = extractelement <2 x i1> zeroinitializer, i64 0
  br label %5

5:                                                ; preds = %.thread
  %6 = select i1 false, i1 false, i1 false
  %7 = select i1 %6, i1 %0, i1 false
  %8 = select i1 %7, i1 %1, i1 false
  %9 = select i1 %8, i1 false, i1 false
  %10 = select i1 %9, i1 %3, i1 false
  %11 = select i1 %10, i1 %4, i1 false
  br i1 %11, label %12, label %13

12:                                               ; preds = %5
  ret void

13:                                               ; preds = %5
  ret void
}

If you build this with opt and run the SLP Vectorizer pass, it generates IR which contains a use of %1 before the definition which then triggers an error about a broken module:

$ ~/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt --passes=slp-vectorizer repro2.ll -o - -S --print-after-all
*** IR Dump After SLPVectorizerPass on _Z3fooP3bar ***
define void @_Z3fooP3bar() {
.thread:
  %0 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %1, <4 x i32> <i32 0, i32 0, i32 0, i32 2>
  %1 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  br label %2

2:                                                ; preds = %.thread
  %3 = select i1 false, i1 false, i1 false
  %4 = freeze <4 x i1> %0
  %5 = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %4)
  %op.rdx = select i1 %5, i1 false, i1 false
  %op.rdx1 = select i1 %3, i1 %op.rdx, i1 false
  br i1 %op.rdx1, label %6, label %7

6:                                                ; preds = %2
  ret void

7:                                                ; preds = %2
  ret void
}
Instruction does not dominate all uses!
  %1 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  %0 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %1, <4 x i32> <i32 0, i32 0, i32 0, i32 2>
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt --passes=slp-vectorizer repro2.ll -o - -S --print-after-all
 #0 0x0000558027a2387f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x35b787f)
 #1 0x0000558027a20fd4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f978c0e5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f978bbb200b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f978bb91859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #5 0x0000558024cd8f26 llvm::RISCVISAInfo::updateImplication() (.cold) RISCVISAInfo.cpp:0:0
 #6 0x00005580279752fe (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x35092fe)
 #7 0x0000558027396d83 (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x2f2ad83)
 #8 0x0000558024db7e16 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x94be16)
 #9 0x000055802735b5ed llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x2eef5ed)
#10 0x0000558024dc39b5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x9579b5)
#11 0x0000558024ce38f3 main (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x8778f3)
#12 0x00007f978bb93083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#13 0x0000558024db6f3e _start (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x94af3e)
Aborted

@valerydmit this appears to be a change you made, can you take a look?

@alexey-bataev
Copy link
Member

Fixed in d79051f

@omern1 omern1 removed their assignment Oct 24, 2023
@tru
Copy link
Collaborator

tru commented Oct 27, 2023

This is tagged in the 17.x release. Should this fix be backported?

@alexey-bataev
Copy link
Member

Yes

@tru
Copy link
Collaborator

tru commented Oct 27, 2023

/cherry-pick d79051f

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2023

Failed to cherry-pick: d79051f

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

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

@EugeneZelenko EugeneZelenko reopened this Oct 27, 2023
@nikic nikic moved this from Needs Triage to Needs Pull Request in LLVM Release Status Oct 31, 2023
@nikic
Copy link
Contributor

nikic commented Oct 31, 2023

/branch nikic/llvm-project/slp-backport

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2023

/pull-request llvm/llvm-project-release-prs#764

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