Skip to content

[ValueTracking] Support scalable vectors for ExtractElement in computeKnownFPClass. #143051

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 3 commits into from
Jun 6, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Jun 6, 2025

We can support scalable vectors by setting the demanded mask to APInt(1, 1) to demand the whole vector.

…teKnownFPClass.

We can support scalable vectors by setting the demanded
mask to APInt(1, 1) to demand the whole vector.
@topperc topperc requested review from arsenm and preames June 6, 2025 00:05
@topperc topperc requested a review from nikic as a code owner June 6, 2025 00:05
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Jun 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: Craig Topper (topperc)

Changes

We can support scalable vectors by setting the demanded mask to APInt(1, 1) to demand the whole vector.


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

1 Files Affected:

  • (modified) llvm/lib/Analysis/ValueTracking.cpp (+7-7)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 0a460786d00ea..30357c170f3d7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5604,19 +5604,19 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
     // Look through extract element. If the index is non-constant or
     // out-of-range demand all elements, otherwise just the extracted element.
     const Value *Vec = Op->getOperand(0);
-    const Value *Idx = Op->getOperand(1);
-    auto *CIdx = dyn_cast<ConstantInt>(Idx);
 
+    APInt DemandedVecElts;
     if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
       unsigned NumElts = VecTy->getNumElements();
-      APInt DemandedVecElts = APInt::getAllOnes(NumElts);
+      DemandedVecElts = APInt::getAllOnes(NumElts);
+      auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(1));
       if (CIdx && CIdx->getValue().ult(NumElts))
         DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
-      return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
-                                 Q, Depth + 1);
-    }
+    } else
+      DemandedVecElts = APInt(1, 1);
 
-    break;
+    return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
+                               Q, Depth + 1);
   }
   case Instruction::InsertElement: {
     if (isa<ScalableVectorType>(Op->getType()))

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

Missing test

@topperc topperc merged commit d5d6f60 into llvm:main Jun 6, 2025
8 checks passed
@topperc topperc deleted the pr/extractelt branch June 6, 2025 03:48
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
…eKnownFPClass. (llvm#143051)

We can support scalable vectors by setting the demanded mask to APInt(1,
1) to demand the whole vector.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
…eKnownFPClass. (llvm#143051)

We can support scalable vectors by setting the demanded mask to APInt(1,
1) to demand the whole vector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants