Skip to content
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

[GlobalISel] Add an assert for the DemandedElts APInt size. #112150

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

davemgreen
Copy link
Collaborator

Similar to the other implementations in DAG/ValueTracking, this adds an assert that the size of the DemandedElts is what we expect it to be - the size of a fixed length vector or APInt(1,1) otherwise. The G_BUILDVECTOR is fixed as it was passing an original DemandedElts for the scalar operands.

Similar to the other implementations in DAG/ValueTracking, this adds an assert
that the size of the DemandedElts is what we expect it to be - the size of a
fixed length vector or APInt(1,1) otherwise. The G_BUILDVECTOR is fixed as it
was passing an original DemandedElts for the scalar operands.
@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2024

@llvm/pr-subscribers-llvm-globalisel

Author: David Green (davemgreen)

Changes

Similar to the other implementations in DAG/ValueTracking, this adds an assert that the size of the DemandedElts is what we expect it to be - the size of a fixed length vector or APInt(1,1) otherwise. The G_BUILDVECTOR is fixed as it was passing an original DemandedElts for the scalar operands.


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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (+12-1)
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
index 35ee85b474d043..52f5d408c8eddd 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -148,6 +148,17 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
   unsigned Opcode = MI.getOpcode();
   LLT DstTy = MRI.getType(R);
 
+#ifndef NDEBUG
+  if (DstTy.isFixedVector()) {
+    assert(
+        DstTy.getNumElements() == DemandedElts.getBitWidth() &&
+        "DemandedElt width should equal the fixed vector number of elements");
+  } else {
+    assert(DemandedElts.getBitWidth() == 1 && DemandedElts == APInt(1, 1) &&
+           "DemandedElt width should be 1 for scalars or scalable vectors");
+  }
+#endif
+
   // Handle the case where this is called on a register that does not have a
   // type constraint (i.e. it has a register class constraint instead). This is
   // unlikely to occur except by looking through copies but it is possible for
@@ -196,7 +207,7 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
       if (!DemandedElts[i])
         continue;
 
-      computeKnownBitsImpl(MI.getOperand(i + 1).getReg(), Known2, DemandedElts,
+      computeKnownBitsImpl(MI.getOperand(i + 1).getReg(), Known2, APInt(1, 1),
                            Depth + 1);
 
       // Known bits are the values that are shared by every demanded element.

@davemgreen davemgreen merged commit 828d72b into llvm:main Oct 14, 2024
10 checks passed
@davemgreen davemgreen deleted the gh-gi-assertknownbitssize branch October 14, 2024 08:59
Stylie777 pushed a commit to Stylie777/llvm-project that referenced this pull request Oct 14, 2024
)

Similar to the other implementations in DAG/ValueTracking, this adds an
assert that the size of the DemandedElts is what we expect it to be -
the size of a fixed length vector or APInt(1,1) otherwise. The
G_BUILDVECTOR is fixed as it was passing an original DemandedElts for
the scalar operands.
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
)

Similar to the other implementations in DAG/ValueTracking, this adds an
assert that the size of the DemandedElts is what we expect it to be -
the size of a fixed length vector or APInt(1,1) otherwise. The
G_BUILDVECTOR is fixed as it was passing an original DemandedElts for
the scalar operands.
bricknerb pushed a commit to bricknerb/llvm-project that referenced this pull request Oct 17, 2024
)

Similar to the other implementations in DAG/ValueTracking, this adds an
assert that the size of the DemandedElts is what we expect it to be -
the size of a fixed length vector or APInt(1,1) otherwise. The
G_BUILDVECTOR is fixed as it was passing an original DemandedElts for
the scalar operands.
EricWF pushed a commit to efcs/llvm-project that referenced this pull request Oct 22, 2024
)

Similar to the other implementations in DAG/ValueTracking, this adds an
assert that the size of the DemandedElts is what we expect it to be -
the size of a fixed length vector or APInt(1,1) otherwise. The
G_BUILDVECTOR is fixed as it was passing an original DemandedElts for
the scalar operands.
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