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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 08:44:16 PDT 2025


https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/142416

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

>From 3ac2a0dad731deea26ca62b7c2161640add623a4 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Mon, 2 Jun 2025 16:33:12 +0100
Subject: [PATCH] [Matrix] Assert that there's shapeinfo in Visit* (NFC).

We should only call Visit* for instructions with shape info. Turn early
exit into assert.
---
 .../Scalar/LowerMatrixIntrinsics.cpp           | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

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);
 



More information about the llvm-commits mailing list