Skip to content

[CVP][LVI] Fix incorrect scalar type when getting constant folded vec #97682

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 4, 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
5 changes: 3 additions & 2 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ LazyValueInfoImpl::getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,

// If V is the condition of the branch itself, then we know exactly what
// it is.
// NB: The condition on a `br` can't be a vector type.
if (Condition == Val)
return ValueLatticeElement::get(ConstantInt::get(
Type::getInt1Ty(Val->getContext()), isTrueDest));
Expand Down Expand Up @@ -1723,7 +1724,7 @@ Constant *LazyValueInfo::getConstant(Value *V, Instruction *CxtI) {
if (Result.isConstantRange()) {
const ConstantRange &CR = Result.getConstantRange();
if (const APInt *SingleVal = CR.getSingleElement())
return ConstantInt::get(V->getContext(), *SingleVal);
return ConstantInt::get(V->getType(), *SingleVal);
}
return nullptr;
}
Expand Down Expand Up @@ -1758,7 +1759,7 @@ Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB,
if (Result.isConstantRange()) {
const ConstantRange &CR = Result.getConstantRange();
if (const APInt *SingleVal = CR.getSingleElement())
return ConstantInt::get(V->getContext(), *SingleVal);
return ConstantInt::get(V->getType(), *SingleVal);
}
return nullptr;
}
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,24 @@ define <2 x i16> @and_with_poison(<2 x i8> %a) {
%res = and <2 x i16> %zext, <i16 u0xff, i16 poison>
ret <2 x i16> %res
}



define <4 x i64> @issue_97674_getConstantOnEdge(i1 %cond) {
entry:
br i1 %cond, label %if.then, label %if.end

if.then:
%folds = add <4 x i64> zeroinitializer, <i64 1, i64 1, i64 1, i64 1>
br label %if.end

if.end:
%r = phi <4 x i64> [ %folds, %if.then ], [ zeroinitializer, %entry ]
ret <4 x i64> %r
}

define <4 x i64> @issue_97674_getConstant() {
entry:
%folds = add <4 x i64> zeroinitializer, zeroinitializer
ret <4 x i64> %folds
}
Loading