forked from OSchip/llvm-project
[ValueTracking] Support select in findAllocaForValue
This commit is contained in:
parent
154901c287
commit
469debe027
|
@ -4345,7 +4345,14 @@ findAllocaForValue(Value *V, DenseMap<Value *, AllocaInst *> &AllocaForValue) {
|
|||
AllocaInst *Res = nullptr;
|
||||
if (CastInst *CI = dyn_cast<CastInst>(V))
|
||||
Res = findAllocaForValue(CI->getOperand(0), AllocaForValue);
|
||||
else if (PHINode *PN = dyn_cast<PHINode>(V)) {
|
||||
else if (auto *SI = dyn_cast<SelectInst>(V)) {
|
||||
Res = findAllocaForValue(SI->getTrueValue(), AllocaForValue);
|
||||
if (!Res)
|
||||
return nullptr;
|
||||
AllocaInst *F = findAllocaForValue(SI->getFalseValue(), AllocaForValue);
|
||||
if (F != Res)
|
||||
return nullptr;
|
||||
} else if (PHINode *PN = dyn_cast<PHINode>(V)) {
|
||||
for (Value *IncValue : PN->incoming_values()) {
|
||||
// Allow self-referencing phi-nodes.
|
||||
if (IncValue == PN)
|
||||
|
|
|
@ -1469,6 +1469,23 @@ const std::pair<const char *, bool> FindAllocaForValueTests[] = {
|
|||
})",
|
||||
true},
|
||||
|
||||
{R"(
|
||||
define void @test(i1 %cond) {
|
||||
%a = alloca i32
|
||||
%r = select i1 %cond, i32* %a, i32* %a
|
||||
ret void
|
||||
})",
|
||||
true},
|
||||
|
||||
{R"(
|
||||
define void @test(i1 %cond) {
|
||||
%a = alloca i32
|
||||
%b = alloca i32
|
||||
%r = select i1 %cond, i32* %a, i32* %b
|
||||
ret void
|
||||
})",
|
||||
false},
|
||||
|
||||
{R"(
|
||||
define void @test(i1 %cond) {
|
||||
entry:
|
||||
|
|
Loading…
Reference in New Issue