Skip to content

[CVP][LVI] Add support for InsertElementInst in LVI #99368

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 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ class LazyValueInfoImpl {
std::optional<ValueLatticeElement> solveBlockValueIntrinsic(IntrinsicInst *II,
BasicBlock *BB);
std::optional<ValueLatticeElement>
solveBlockValueInsertElement(InsertElementInst *IEI, BasicBlock *BB);
std::optional<ValueLatticeElement>
solveBlockValueExtractValue(ExtractValueInst *EVI, BasicBlock *BB);
bool isNonNullAtEndOfBlock(Value *Val, BasicBlock *BB);
void intersectAssumeOrGuardBlockValueConstantRange(Value *Val,
Expand Down Expand Up @@ -657,6 +659,9 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) {
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(BBI))
return solveBlockValueBinaryOp(BO, BB);

if (auto *IEI = dyn_cast<InsertElementInst>(BBI))
return solveBlockValueInsertElement(IEI, BB);

if (auto *EVI = dyn_cast<ExtractValueInst>(BBI))
return solveBlockValueExtractValue(EVI, BB);

Expand Down Expand Up @@ -1038,6 +1043,24 @@ LazyValueInfoImpl::solveBlockValueIntrinsic(IntrinsicInst *II, BasicBlock *BB) {
MetadataVal);
}

std::optional<ValueLatticeElement>
LazyValueInfoImpl::solveBlockValueInsertElement(InsertElementInst *IEI,
BasicBlock *BB) {
std::optional<ValueLatticeElement> OptEltVal =
getBlockValue(IEI->getOperand(1), BB, IEI);
if (!OptEltVal)
return std::nullopt;
ValueLatticeElement &Res = *OptEltVal;

std::optional<ValueLatticeElement> OptVecVal =
getBlockValue(IEI->getOperand(0), BB, IEI);
if (!OptVecVal)
return std::nullopt;

Res.mergeIn(*OptVecVal);
return Res;
}

std::optional<ValueLatticeElement>
LazyValueInfoImpl::solveBlockValueExtractValue(ExtractValueInst *EVI,
BasicBlock *BB) {
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,28 @@ join:
%add = add <2 x i16> %phi, <i16 2, i16 3>
ret <2 x i16> %add
}

;; Check if ICMP instruction is constant folded or not.
define <2 x i1> @insertelement_fold1() {
; CHECK-LABEL: define <2 x i1> @insertelement_fold1() {
; CHECK-NEXT: [[IE1:%.*]] = insertelement <2 x i32> poison, i32 10, i64 0
; CHECK-NEXT: [[IE2:%.*]] = insertelement <2 x i32> [[IE1]], i32 20, i64 1
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%ie1 = insertelement <2 x i32> poison, i32 10, i64 0
%ie2 = insertelement <2 x i32> %ie1, i32 20, i64 1
%icmp1 = icmp slt <2 x i32> %ie2, <i32 1024, i32 1024>
ret <2 x i1> %icmp1
}

;; Check if LVI is able to handle constant vector operands
;; in InsertElementInst and CVP is able to fold ICMP instruction.
define <2 x i1> @insertelement_fold2() {
; CHECK-LABEL: define <2 x i1> @insertelement_fold2() {
; CHECK-NEXT: [[IE1:%.*]] = insertelement <2 x i32> <i32 poison, i32 20>, i32 10, i64 0
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%ie1 = insertelement <2 x i32> <i32 poison, i32 20>, i32 10, i64 0
%icmp1 = icmp slt <2 x i32> %ie1, <i32 1024, i32 1024>
ret <2 x i1> %icmp1
}
Loading