aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2021-04-10 00:31:56 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2021-04-10 00:56:28 +0300
commit077bff39d46364035a5dcfa32fc69910ad0975d0 (patch)
treebb125d668e537244529013b0265ab57bbffa494c /llvm/lib/Analysis/Loads.cpp
parent99d6e31e0bd02d484c213a7446fd707c62dec45b (diff)
downloadllvm-077bff39d46364035a5dcfa32fc69910ad0975d0.zip
llvm-077bff39d46364035a5dcfa32fc69910ad0975d0.tar.gz
llvm-077bff39d46364035a5dcfa32fc69910ad0975d0.tar.bz2
[Analysis] isDereferenceableAndAlignedPointer(): recurse into select's hands
By doing this within the method itself, we support traversing multiple levels of selects (TODO: PHI's), fixing the SROA `std::clamp()` testcase. Fixes https://bugs.llvm.org/show_bug.cgi?id=47271 Mostly fixes https://bugs.llvm.org/show_bug.cgi?id=49909
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 8d01ea0..2ae1fd5 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -59,6 +59,16 @@ static bool isDereferenceableAndAlignedPointer(
// Note that it is not safe to speculate into a malloc'd region because
// malloc may return null.
+ // Recurse into both hands of select.
+ if (const SelectInst *Sel = dyn_cast<SelectInst>(V)) {
+ return isDereferenceableAndAlignedPointer(Sel->getTrueValue(), Alignment,
+ Size, DL, CtxI, DT, TLI, Visited,
+ MaxDepth) &&
+ isDereferenceableAndAlignedPointer(Sel->getFalseValue(), Alignment,
+ Size, DL, CtxI, DT, TLI, Visited,
+ MaxDepth);
+ }
+
// bitcast instructions are no-ops as far as dereferenceability is concerned.
if (const BitCastOperator *BC = dyn_cast<BitCastOperator>(V)) {
if (BC->getSrcTy()->isPointerTy())