Skip to content

[Matrix] Assert that there's shapeinfo in Visit* (NFC). #142416

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 1 commit into from
Jun 2, 2025

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Jun 2, 2025

We should only call Visit* for instructions with shape info. Turn early exit into assert.

We should only call Visit* for instructions with shape info. Turn early
exit into assert.
@fhahn fhahn requested review from jroelofs and anemet June 2, 2025 15:44
fhahn added a commit to fhahn/llvm-project that referenced this pull request Jun 2, 2025
Visit* are always modifying the IR, remove the boolean result.

Depends on llvm#142416.
@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Florian Hahn (fhahn)

Changes

We should only call Visit* for instructions with shape info. Turn early exit into assert.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+8-10)
diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 787e107464c0a..fb5e081acf7c5 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -2107,9 +2107,8 @@ class LowerMatrixIntrinsics {
   /// Lower load instructions, if shape information is available.
   bool VisitLoad(LoadInst *Inst, Value *Ptr, IRBuilder<> &Builder) {
     auto I = ShapeMap.find(Inst);
-    if (I == ShapeMap.end())
-      return false;
-
+    assert(I != ShapeMap.end() &&
+           "must only visit instructions with shape info");
     LowerLoad(Inst, Ptr, Inst->getAlign(),
               Builder.getInt64(I->second.getStride()), Inst->isVolatile(),
               I->second);
@@ -2119,9 +2118,8 @@ class LowerMatrixIntrinsics {
   bool VisitStore(StoreInst *Inst, Value *StoredVal, Value *Ptr,
                   IRBuilder<> &Builder) {
     auto I = ShapeMap.find(StoredVal);
-    if (I == ShapeMap.end())
-      return false;
-
+    assert(I != ShapeMap.end() &&
+           "must only visit instructions with shape info");
     LowerStore(Inst, StoredVal, Ptr, Inst->getAlign(),
                Builder.getInt64(I->second.getStride()), Inst->isVolatile(),
                I->second);
@@ -2131,8 +2129,8 @@ class LowerMatrixIntrinsics {
   /// Lower binary operators, if shape information is available.
   bool VisitBinaryOperator(BinaryOperator *Inst) {
     auto I = ShapeMap.find(Inst);
-    if (I == ShapeMap.end())
-      return false;
+    assert(I != ShapeMap.end() &&
+           "must only visit instructions with shape info");
 
     Value *Lhs = Inst->getOperand(0);
     Value *Rhs = Inst->getOperand(1);
@@ -2163,8 +2161,8 @@ class LowerMatrixIntrinsics {
   /// Lower unary operators, if shape information is available.
   bool VisitUnaryOperator(UnaryOperator *Inst) {
     auto I = ShapeMap.find(Inst);
-    if (I == ShapeMap.end())
-      return false;
+    assert(I != ShapeMap.end() &&
+           "must only visit instructions with shape info");
 
     Value *Op = Inst->getOperand(0);
 

@fhahn fhahn merged commit adba40e into llvm:main Jun 2, 2025
13 checks passed
@fhahn fhahn deleted the matrix-remove-check branch June 2, 2025 17:18
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 2, 2025
…142416)

We should only call Visit* for instructions with shape info. Turn early
exit into assert.

PR: llvm/llvm-project#142416
sallto pushed a commit to sallto/llvm-project that referenced this pull request Jun 3, 2025
We should only call Visit* for instructions with shape info. Turn early
exit into assert.

PR: llvm#142416
Copy link
Contributor Author

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

Argh, found a case that triggers the assertions :(

working on a reproducer

fhahn added a commit to fhahn/llvm-project that referenced this pull request Jun 3, 2025
ShapeInfo for the store operand may be dropped, e.g. because the operand
got folded by transpose optimizations to another instruction w/o shape
info. This was exposed by the assertion added in
llvm#142416.

This updates VisitStore to use the shape-info directly from the
instruction, which is in line with the other Visit* functions and
ensures that we won't lose shape info.
fhahn added a commit that referenced this pull request Jun 4, 2025
ShapeInfo for the store operand may be dropped, e.g. because the operand
got folded by transpose optimizations to another instruction w/o shape
info. This was exposed by the assertion added in
#142416.

This updates VisitStore to use the shape-info directly from the
instruction, which is in line with the other Visit* functions and
ensures that we won't lose shape info.

PR: #142664
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 4, 2025
ShapeInfo for the store operand may be dropped, e.g. because the operand
got folded by transpose optimizations to another instruction w/o shape
info. This was exposed by the assertion added in
llvm/llvm-project#142416.

This updates VisitStore to use the shape-info directly from the
instruction, which is in line with the other Visit* functions and
ensures that we won't lose shape info.

PR: llvm/llvm-project#142664
fhahn added a commit to fhahn/llvm-project that referenced this pull request Jun 5, 2025
Visit* are always modifying the IR, remove the boolean result.

Depends on llvm#142416.
fhahn added a commit that referenced this pull request Jun 5, 2025
…42417)

Visit* are always modifying the IR, remove the boolean result.

Depends on #142416.

PR: #142417
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 5, 2025
… (NFC). (#142417)

Visit* are always modifying the IR, remove the boolean result.

Depends on llvm/llvm-project#142416.

PR: llvm/llvm-project#142417
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