aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-05-31 11:18:53 +0200
committerNikita Popov <npopov@redhat.com>2023-05-31 11:21:35 +0200
commitdc81e69eb126ea1dbab202733ae34b1a3d6eb0cf (patch)
tree2fce5cdcaeaadc1d5967f40016e81bd925f159a2 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parent8d7e90c3b5d22e31c6af25c2f95b8047038590c4 (diff)
downloadllvm-dc81e69eb126ea1dbab202733ae34b1a3d6eb0cf.zip
llvm-dc81e69eb126ea1dbab202733ae34b1a3d6eb0cf.tar.gz
llvm-dc81e69eb126ea1dbab202733ae34b1a3d6eb0cf.tar.bz2
[IndVars] Check expansion safety in makeIVComparisonInvariant() (PR62992)
Make sure the invariant expressions are safe to expand. In particular, we should not speculative a trapping division into the preheader. Fixes https://github.com/llvm/llvm-project/issues/62992.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 1458e61..62821f1 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -217,8 +217,10 @@ bool SimplifyIndvar::makeIVComparisonInvariant(ICmpInst *ICmp,
// Do not generate something ridiculous.
auto *PHTerm = Preheader->getTerminator();
- if (Rewriter.isHighCostExpansion({ InvariantLHS, InvariantRHS }, L,
- 2 * SCEVCheapExpansionBudget, TTI, PHTerm))
+ if (Rewriter.isHighCostExpansion({InvariantLHS, InvariantRHS}, L,
+ 2 * SCEVCheapExpansionBudget, TTI, PHTerm) ||
+ !Rewriter.isSafeToExpandAt(InvariantLHS, PHTerm) ||
+ !Rewriter.isSafeToExpandAt(InvariantRHS, PHTerm))
return false;
auto *NewLHS =
Rewriter.expandCodeFor(InvariantLHS, IVOperand->getType(), PHTerm);