Skip to content

[SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. #99424

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

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

HanKuanChen
Copy link
Contributor

The argument V may come from adjustExtracts, which is the vector operand of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>, ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: #99411

@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Han-Kuan Chen (HanKuanChen)

Changes

The argument V may come from adjustExtracts, which is the vector operand of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>, ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: #99411


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+1-1)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ccb6734d5618c..a09bb00f3419e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11850,7 +11850,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
   Value *castToScalarTyElem(Value *V,
                             std::optional<bool> IsSigned = std::nullopt) {
     auto *VecTy = cast<VectorType>(V->getType());
-    assert(getNumElements(ScalarTy) < getNumElements(VecTy) &&
+    assert(getNumElements(ScalarTy) <= getNumElements(VecTy) &&
            (getNumElements(VecTy) % getNumElements(ScalarTy) == 0));
     if (VecTy->getElementType() == ScalarTy->getScalarType())
       return V;

@HanKuanChen HanKuanChen force-pushed the slp-revec-fix-99411 branch from 20d17f5 to 049e1cc Compare July 18, 2024 03:52
@dyung
Copy link
Collaborator

dyung commented Jul 18, 2024

Should we add either or both of the crashing examples as tests?

The argument V may come from adjustExtracts, which is the vector operand
of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>,
ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: llvm#99411
@HanKuanChen HanKuanChen force-pushed the slp-revec-fix-99411 branch from 049e1cc to 79d1708 Compare July 18, 2024 05:25
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

@HanKuanChen HanKuanChen merged commit b634e05 into llvm:main Jul 18, 2024
5 of 6 checks passed
@HanKuanChen HanKuanChen deleted the slp-revec-fix-99411 branch July 18, 2024 11:54
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 18, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/2111

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: Transforms/SLPVectorizer/revec-fix-99411.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt: warning: failed to infer data layout: unable to get target for 'x86_64-unknown-linux-gnu', see --version and --triple.
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt: WARNING: failed to create target machine for 'x86_64-unknown-linux-gnu': unable to get target for 'x86_64-unknown-linux-gnu', see --version and --triple.
�[1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll:7:15: �[0m�[0;1;31merror: �[0m�[1mCHECK-NEXT: expected string not found in input
�[0m; CHECK-NEXT: store <2 x i64> zeroinitializer, ptr null, align 8
�[0;1;32m              ^
�[0m�[1m<stdin>:6:7: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0mentry:
�[0;1;32m      ^
�[0m�[1m<stdin>:7:19: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m %0 = extractelement <1 x i64> zeroinitializer, i64 0
�[0;1;32m                  ^
�[0m
Input file: <stdin>
Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m           1: �[0m�[1m�[0;1;46m; ModuleID = '/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll' �[0m
�[0;1;30m           2: �[0m�[1m�[0;1;46msource_filename = "/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll" �[0m
�[0;1;30m           3: �[0m�[1m�[0;1;46mtarget triple = "x86_64-unknown-linux-gnu" �[0m
�[0;1;30m           4: �[0m�[1m�[0;1;46m �[0m
�[0;1;30m           5: �[0m�[1m�[0;1;46mdefine void �[0m@e(�[0;1;46m) { �[0m
�[0;1;32mlabel:5'0                 ^~~
�[0m�[0;1;32mlabel:5'1                 ^~~
�[0m�[0;1;30m           6: �[0m�[1m�[0;1;46m�[0mentry:�[0;1;46m �[0m
�[0;1;32mnext:6        ^~~~~~
�[0m�[0;1;31mnext:7'0            X error: no match found
�[0m�[0;1;30m           7: �[0m�[1m�[0;1;46m %0 = extractelement <1 x i64> zeroinitializer, i64 0 �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;35mnext:7'1                        ?                                    possible intended match
�[0m�[0;1;30m           8: �[0m�[1m�[0;1;46m %bf.value = and i64 %0, 0 �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           9: �[0m�[1m�[0;1;46m %bf.set = or i64 0, %bf.value �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          10: �[0m�[1m�[0;1;46m store i64 %bf.set, ptr getelementptr inbounds (i8, ptr null, i64 8), align 8 �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          11: �[0m�[1m�[0;1;46m %bf.value2 = and i64 0, 0 �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          12: �[0m�[1m�[0;1;46m %bf.set4 = or i64 0, %bf.value2 �[0m
�[0;1;31mnext:7'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

@dyung
Copy link
Collaborator

dyung commented Jul 18, 2024

@HanKuanChen the test you added is failing on at least one buildbot, see the message above (I happen to manage that build bot). Can you take a look so that I don't have to revert your change?

@amykhuang
Copy link
Collaborator

looks good for me, aside from the test issue

yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…m. (#99424)

Summary:
The argument V may come from adjustExtracts, which is the vector operand
of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>,
ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: #99411

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250836
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.

6 participants