[ValueTracking] Support select in findAllocaForValue

This commit is contained in:
Vitaly Buka 2020-08-27 02:01:26 -07:00
parent 154901c287
commit 469debe027
2 changed files with 25 additions and 1 deletions

View File

@ -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)

View File

@ -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: