Skip to content

Commit 8858340

Browse files
committed
[SCEV] Swap operands if LHS is not unknown.
Currently we only use information from guards for unknown expressions. Swap LHS/RHS and predicate, if LHS is not unknown.
1 parent 8c53282 commit 8858340

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12593,6 +12593,11 @@ const SCEV* ScalarEvolution::computeMaxBackedgeTakenCount(const Loop *L) {
1259312593
const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
1259412594
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
1259512595
const SCEV *RHS, ValueToSCEVMapTy &RewriteMap) {
12596+
if (!isa<SCEVUnknown>(LHS)) {
12597+
std::swap(LHS, RHS);
12598+
Predicate = CmpInst::getSwappedPredicate(Predicate);
12599+
}
12600+
1259612601
// For now, limit to conditions that provide information about unknown
1259712602
// expressions.
1259812603
auto *LHSUnknown = dyn_cast<SCEVUnknown>(LHS);

llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exit:
2828
define void @test_guard_less_than_16_operands_swapped(i32* nocapture %a, i64 %i) {
2929
; CHECK-LABEL: Determining loop execution counts for: @test_guard_less_than_16_operands_swapped
3030
; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i))
31-
; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
31+
; CHECK-NEXT: Loop %loop: max backedge-taken count is 15
3232
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (15 + (-1 * %i))
3333
;
3434
entry:

0 commit comments

Comments
 (0)