Skip to content

Conversation

@valerydmit
Copy link
Contributor

Test exposes issue with delayed gather emission, which may lead to generating an instruction which does not dominate all users.

Test exposes issue with delayed gather emission, which may lead
to generating an instruction which does not dominate all users.
@alexey-bataev
Copy link
Member

I think it is fixed already, no?

@llvmbot
Copy link
Member

llvmbot commented Oct 24, 2023

@llvm/pr-subscribers-llvm-transforms

Author: Valery Dmitriev (valerydmit)

Changes

Test exposes issue with delayed gather emission, which may lead to generating an instruction which does not dominate all users.


Full diff: https://github.com/llvm/llvm-project/pull/70088.diff

1 Files Affected:

  • (added) llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll (+59)
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll b/llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll
new file mode 100644
index 000000000000000..8860cd4d8d141e3
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll
@@ -0,0 +1,59 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -passes=slp-vectorizer -mtriple=x86_64 -mattr=+avx2 -S < %s | FileCheck %s
+
+; Test case for issue #69670.
+
+; #69392 uncovered a problem with delayed gather nodes emission, specifically
+; when the node is a PHI operand, which depends on another gathered node,
+; also an operand of a PHI (in another block).
+
+define void @test() {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DOTPRE_PRE:%.*]] = load float, ptr poison, align 4
+; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x float> <float poison, float undef>, float [[DOTPRE_PRE]], i32 0
+; CHECK-NEXT:    br label [[BB1:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi <2 x float> [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP10:%.*]], [[BB2:%.*]] ]
+; CHECK-NEXT:    br label [[BB2]]
+; CHECK:       bb2:
+; CHECK-NEXT:    [[TMP2:%.*]] = phi <2 x float> [ [[TMP1]], [[BB1]] ], [ [[TMP9:%.*]], [[BB2]] ]
+; CHECK-NEXT:    [[I1:%.*]] = load float, ptr poison, align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x float> [[TMP2]], <2 x float> poison, <2 x i32> <i32 1, i32 poison>
+; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x float> [[TMP3]], float [[I1]], i32 1
+; CHECK-NEXT:    [[TMP5:%.*]] = fdiv <2 x float> [[TMP2]], [[TMP4]]
+; CHECK-NEXT:    [[TMP6:%.*]] = extractelement <2 x float> [[TMP5]], i32 0
+; CHECK-NEXT:    [[TMP7:%.*]] = extractelement <2 x float> [[TMP5]], i32 1
+; CHECK-NEXT:    [[MUL:%.*]] = fmul float [[TMP6]], [[TMP7]]
+; CHECK-NEXT:    tail call void @foo(float [[MUL]])
+; CHECK-NEXT:    [[I2:%.*]] = load float, ptr poison, align 4
+; CHECK-NEXT:    [[TOBOOL:%.*]] = fcmp une float [[I2]], 0.000000e+00
+; CHECK-NEXT:    [[TMP8:%.*]] = insertelement <2 x float> poison, float [[I2]], i32 0
+; CHECK-NEXT:    [[TMP9]] = shufflevector <2 x float> [[TMP8]], <2 x float> [[TMP5]], <2 x i32> <i32 0, i32 2>
+; CHECK-NEXT:    [[TMP10]] = shufflevector <2 x float> [[TMP8]], <2 x float> [[TMP2]], <2 x i32> <i32 0, i32 3>
+; CHECK-NEXT:    br i1 [[TOBOOL]], label [[BB1]], label [[BB2]]
+;
+entry:
+  %.pre.pre = load float, ptr poison, align 4
+  br label %bb1
+
+bb1:                                              ; preds = %bb2, %entry
+  %.pre = phi float [ %.pre.pre, %entry ], [ %i2, %bb2 ]
+  %foxtrot.0 = phi float [ undef, %entry ], [ %gulf.0, %bb2 ]
+  br label %bb2
+
+bb2:                                              ; preds = %bb2, %bb1
+  %i = phi float [ %.pre, %bb1 ], [ %i2, %bb2 ]
+  %gulf.0 = phi float [ %foxtrot.0, %bb1 ], [ %div, %bb2 ]
+  %div = fdiv float %i, %gulf.0
+  %i1 = load float, ptr poison, align 4
+  %div1 = fdiv float %gulf.0, %i1
+  %mul = fmul float %div, %div1
+  tail call void @foo(float %mul)
+  %i2 = load float, ptr poison, align 4
+  %tobool = fcmp une float %i2, 0.000000e+00
+  br i1 %tobool, label %bb1, label %bb2
+}
+
+declare void @foo(float)

Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@valerydmit
Copy link
Contributor Author

I think it is fixed already, no?
I have a fix. The crash is only reproducible with #69392 (which was reverted). Will publish it soon along with the re-commit.

@valerydmit valerydmit merged commit 117041d into llvm:main Oct 24, 2023
@valerydmit valerydmit deleted the iss69670_test_case branch October 24, 2023 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants