[llvm] 469debe - [ValueTracking] Support select in findAllocaForValue
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 02:14:06 PDT 2020
Author: Vitaly Buka
Date: 2020-08-27T02:13:52-07:00
New Revision: 469debe0275b5800a2231ae670d235a83e6fbb27
URL: https://github.com/llvm/llvm-project/commit/469debe0275b5800a2231ae670d235a83e6fbb27
DIFF: https://github.com/llvm/llvm-project/commit/469debe0275b5800a2231ae670d235a83e6fbb27.diff
LOG: [ValueTracking] Support select in findAllocaForValue
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 36998cd90697..5be566b693f4 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -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)
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 732f71e4de90..7951d6dec1f8 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -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:
More information about the llvm-commits
mailing list