Skip to content

Commit e4db938

Browse files
committed
[ValueTracking] Support non-constant idx for computeKnownFPClass of insertelement
Its same logic as before, we just need to intersect what we know about the new Elt and the entire pre-existing Vec. Closes #87708
1 parent d5b48ce commit e4db938

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,14 +5355,17 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
53555355
const Value *Vec = Op->getOperand(0);
53565356
const Value *Elt = Op->getOperand(1);
53575357
auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(2));
5358-
// Early out if the index is non-constant or out-of-range.
53595358
unsigned NumElts = DemandedElts.getBitWidth();
5360-
if (!CIdx || CIdx->getValue().uge(NumElts))
5361-
return;
5359+
APInt DemandedVecElts = DemandedElts;
5360+
bool NeedsElt = true;
5361+
// If we know the index we are inserting to, clear it from Vec check.
5362+
if (CIdx && CIdx->getValue().ult(NumElts)) {
5363+
DemandedVecElts.clearBit(CIdx->getZExtValue());
5364+
NeedsElt = DemandedElts[CIdx->getZExtValue()];
5365+
}
53625366

5363-
unsigned EltIdx = CIdx->getZExtValue();
53645367
// Do we demand the inserted element?
5365-
if (DemandedElts[EltIdx]) {
5368+
if (NeedsElt) {
53665369
computeKnownFPClass(Elt, Known, InterestedClasses, Depth + 1, Q);
53675370
// If we don't know any bits, early out.
53685371
if (Known.isUnknown())
@@ -5371,10 +5374,8 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
53715374
Known.KnownFPClasses = fcNone;
53725375
}
53735376

5374-
// We don't need the base vector element that has been inserted.
5375-
APInt DemandedVecElts = DemandedElts;
5376-
DemandedVecElts.clearBit(EltIdx);
5377-
if (!!DemandedVecElts) {
5377+
// Do we need anymore elements from Vec?
5378+
if (!DemandedVecElts.isZero()) {
53785379
KnownFPClass Known2;
53795380
computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
53805381
Depth + 1, Q);

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ define <4 x float> @insertelement_constant_chain() {
15151515

15161516
define <4 x float> @insertelement_non_constant_chain(i32 %idx) {
15171517
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1518-
; CHECK-LABEL: define <4 x float> @insertelement_non_constant_chain
1518+
; CHECK-LABEL: define nofpclass(nan inf nzero sub) <4 x float> @insertelement_non_constant_chain
15191519
; CHECK-SAME: (i32 [[IDX:%.*]]) #[[ATTR3]] {
15201520
; CHECK-NEXT: [[INS_0:%.*]] = insertelement <4 x float> poison, float 1.000000e+00, i32 0
15211521
; CHECK-NEXT: [[INS_1:%.*]] = insertelement <4 x float> [[INS_0]], float 0.000000e+00, i32 1
@@ -1601,7 +1601,7 @@ define float @insertelement_extractelement_unknown(<4 x float> nofpclass(zero) %
16011601

16021602
define <4 x float> @insertelement_index_oob_chain() {
16031603
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1604-
; CHECK-LABEL: define <4 x float> @insertelement_index_oob_chain
1604+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub norm) <4 x float> @insertelement_index_oob_chain
16051605
; CHECK-SAME: () #[[ATTR3]] {
16061606
; CHECK-NEXT: [[INSERT:%.*]] = insertelement <4 x float> zeroinitializer, float 0x7FF0000000000000, i32 4
16071607
; CHECK-NEXT: ret <4 x float> [[INSERT]]

0 commit comments

Comments
 (0)