Skip to content

Commit d5d6f60

Browse files
authored
[ValueTracking] Support scalable vectors for ExtractElement in computeKnownFPClass. (#143051)
We can support scalable vectors by setting the demanded mask to APInt(1, 1) to demand the whole vector.
1 parent ea709c7 commit d5d6f60

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,19 +5604,20 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
56045604
// Look through extract element. If the index is non-constant or
56055605
// out-of-range demand all elements, otherwise just the extracted element.
56065606
const Value *Vec = Op->getOperand(0);
5607-
const Value *Idx = Op->getOperand(1);
5608-
auto *CIdx = dyn_cast<ConstantInt>(Idx);
56095607

5608+
APInt DemandedVecElts;
56105609
if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
56115610
unsigned NumElts = VecTy->getNumElements();
5612-
APInt DemandedVecElts = APInt::getAllOnes(NumElts);
5611+
DemandedVecElts = APInt::getAllOnes(NumElts);
5612+
auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(1));
56135613
if (CIdx && CIdx->getValue().ult(NumElts))
56145614
DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
5615-
return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
5616-
Q, Depth + 1);
5615+
} else {
5616+
DemandedVecElts = APInt(1, 1);
56175617
}
56185618

5619-
break;
5619+
return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
5620+
Q, Depth + 1);
56205621
}
56215622
case Instruction::InsertElement: {
56225623
if (isa<ScalableVectorType>(Op->getType()))

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ define float @returned_extractelement_index_oob(<4 x float> nofpclass(nan) %vec)
14741474

14751475
define float @returned_extractelement_scalable(<vscale x 4 x float> nofpclass(nan) %vec) {
14761476
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1477-
; CHECK-LABEL: define float @returned_extractelement_scalable
1477+
; CHECK-LABEL: define nofpclass(nan) float @returned_extractelement_scalable
14781478
; CHECK-SAME: (<vscale x 4 x float> nofpclass(nan) [[VEC:%.*]]) #[[ATTR3]] {
14791479
; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <vscale x 4 x float> [[VEC]], i32 0
14801480
; CHECK-NEXT: ret float [[EXTRACT]]

0 commit comments

Comments
 (0)