Skip to content

"Instruction does not dominate all uses" after Complex Deinterleaving Pass #65044

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

Closed
danilaml opened this issue Aug 28, 2023 · 8 comments · Fixed by llvm/llvm-project-release-prs#674

Comments

@danilaml
Copy link
Collaborator

danilaml commented Aug 28, 2023

For the following IR:

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "aarch64-none-linux-gnu"

define void @foo() #0 {
bb:
  br label %bb173

bb173:                                            ; preds = %bb173, %bb
  %phi177 = phi <2 x i32> [ %add190, %bb173 ], [ zeroinitializer, %bb ]
  %phi178 = phi <2 x i32> [ %add187, %bb173 ], [ zeroinitializer, %bb ]
  %add185 = add <2 x i32> %phi178, <i32 1, i32 1>
  %add186 = add <2 x i32> %phi177, <i32 1, i32 1>
  %shufflevector = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
  %add187 = add <2 x i32> %add185, %shufflevector
  %shufflevector189 = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
  %add190 = add <2 x i32> %add186, %shufflevector189
  br i1 poison, label %bb193, label %bb173

bb193:                                            ; preds = %bb173
  %add194 = or <2 x i32> %add190, %add187
  store volatile i32 0, ptr null, align 4
  unreachable
}

attributes #0 = { "target-cpu"="neoverse-v1" }

Complex deinterleaving produced broken code:

identifyNode on   %add187 = add <2 x i32> %add185, %shufflevector /   %add190 = add <2 x i32> %add186, %shufflevector189
identifyNode on   %add185 = add <2 x i32> %phi178, <i32 1, i32 1> /   %add186 = add <2 x i32> %phi177, <i32 1, i32 1>
identifyNode on   %phi178 = phi <2 x i32> [ %add187, %bb173 ], [ zeroinitializer, %bb ] /   %phi177 = phi <2 x i32> [ %add190, %bb173 ], [ zeroinitializer, %bb ]
identifyNode on <2 x i32> <i32 1, i32 1> / <2 x i32> <i32 1, i32 1>
identifyNode on   %shufflevector = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer /   %shufflevector189 = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
Identified reduction starting from instructions:   %add187 = add <2 x i32> %add185, %shufflevector /   %add190 = add <2 x i32> %add186, %shufflevector189
Verifying parent property of node %bb173
Verifying parent property of node %bb
*** IR Dump After Complex Deinterleaving Pass (complex-deinterleaving) ***
define void @foo() #0 {
bb:
  %0 = call <4 x i32> @llvm.experimental.vector.interleave2.v4i32(<2 x i32> zeroinitializer, <2 x i32> zeroinitializer)
  br label %bb173

bb173:                                            ; preds = %bb173, %bb
  %1 = phi <4 x i32> [ %0, %bb ], [ %4, %bb173 ]
  %shufflevector = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
  %2 = call <4 x i32> @llvm.experimental.vector.interleave2.v4i32(<2 x i32> <i32 1, i32 1>, <2 x i32> <i32 1, i32 1>)
  %3 = add <4 x i32> %1, %2
  %4 = add <4 x i32> %3, %5
  %shufflevector189 = shufflevector <2 x i32> zeroinitializer, <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
  %5 = call <4 x i32> @llvm.experimental.vector.interleave2.v4i32(<2 x i32> %shufflevector, <2 x i32> %shufflevector189)
  br i1 true, label %bb193, label %bb173

bb193:                                            ; preds = %bb173
  %6 = call { <2 x i32>, <2 x i32> } @llvm.experimental.vector.deinterleave2.v4i32(<4 x i32> %4)
  %7 = extractvalue { <2 x i32>, <2 x i32> } %6, 0
  %8 = extractvalue { <2 x i32>, <2 x i32> } %6, 1
  %add194 = or <2 x i32> %8, %7
  store volatile i32 0, ptr null, align 4
  unreachable
}
... eventually
Instruction does not dominate all uses!
  %4 = call <4 x i32> @llvm.experimental.vector.interleave2.v4i32(<2 x i32> %shufflevector, <2 x i32> %shufflevector189)
  %3 = add <4 x i32> %2, %4
in function foo
LLVM ERROR: Broken function found, compilation aborted!

Godbolt link https://godbolt.org/z/7zbbePPd6

Bisect pointed to c15557d by @igogo-x86

@danilaml
Copy link
Collaborator Author

Looks like it's because and extra builder is created for insertion here:

Instruction *InsertPoint = (I->comesBefore(R) ? R : I)->getNextNode();

While the method that replaced operands uses the main builder to insert the main function. Don't know if the fix is as simple as changing the insertion point of the main builder (or perhaps recalculating it based on the operands).

@llvmbot
Copy link
Member

llvmbot commented Aug 30, 2023

@llvm/issue-subscribers-backend-aarch64

@igogo-x86 igogo-x86 self-assigned this Aug 30, 2023
@igogo-x86
Copy link
Contributor

Thanks, I am on it

@danilaml
Copy link
Collaborator Author

@igogo-x86 in case you've missed it, I've submitted a potential fix for review here: https://reviews.llvm.org/D159123

@igogo-x86
Copy link
Contributor

I have a fix here - https://reviews.llvm.org/D159209

@igogo-x86 igogo-x86 added this to the LLVM 17.0.X Release milestone Aug 31, 2023
@igogo-x86
Copy link
Contributor

/cherry-pick 2fce8f7 e2cb07c

@igogo-x86 igogo-x86 reopened this Aug 31, 2023
@llvmbot
Copy link
Member

llvmbot commented Aug 31, 2023

/branch llvm/llvm-project-release-prs/issue65044

llvmbot pushed a commit to llvm/llvm-project-release-prs that referenced this issue Aug 31, 2023
… in ComplexDeinterleavingPass

When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it
either from the Real or Imaginary part. The correct way is to take whichever
is later in the BasicBlock, but before the patch, we just always took the
Real part.

Fixes llvm/llvm-project#65044

Differential Revision: https://reviews.llvm.org/D159209

(cherry picked from commit e2cb07c322e85604dc48f9caec52b3570db0e1d8)
@llvmbot
Copy link
Member

llvmbot commented Aug 31, 2023

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

@tru tru moved this from Needs Triage to Needs Review in LLVM Release Status Sep 5, 2023
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Sep 5, 2023
tru pushed a commit to llvm/llvm-project-release-prs that referenced this issue Sep 11, 2023
… in ComplexDeinterleavingPass

When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it
either from the Real or Imaginary part. The correct way is to take whichever
is later in the BasicBlock, but before the patch, we just always took the
Real part.

Fixes llvm/llvm-project#65044

Differential Revision: https://reviews.llvm.org/D159209

(cherry picked from commit e2cb07c322e85604dc48f9caec52b3570db0e1d8)
tru pushed a commit that referenced this issue Sep 11, 2023
@tru tru moved this from Needs Review to Done in LLVM Release Status Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

5 participants