Skip to content

Commit ea17ced

Browse files
add test, address comments
1 parent 231503f commit ea17ced

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6031,7 +6031,7 @@ const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
60316031
const SCEV *
60326032
ScalarEvolution::createNodeForPHIWithIdenticalOperands(PHINode *PN) {
60336033
BinaryOperator *CommonInst = nullptr;
6034-
// check if instructions are identical
6034+
// Check if instructions are identical.
60356035
for (Value *Incoming : PN->incoming_values()) {
60366036
auto *IncomingInst = dyn_cast<BinaryOperator>(Incoming);
60376037
if (!IncomingInst)
@@ -6047,10 +6047,9 @@ ScalarEvolution::createNodeForPHIWithIdenticalOperands(PHINode *PN) {
60476047
if (!CommonInst)
60486048
return nullptr;
60496049

6050-
// check if SCEV exprs for instructions are identical
6050+
// Check if SCEV exprs for instructions are identical.
60516051
const SCEV *CommonSCEV = getSCEV(CommonInst);
6052-
bool SCEVExprsIdentical = std::all_of(
6053-
PN->incoming_values().begin(), PN->incoming_values().end(),
6052+
bool SCEVExprsIdentical = all_of(drop_begin(PN->incoming_values()),
60546053
[this, CommonSCEV](Value *V) { return CommonSCEV == getSCEV(V); });
60556054
return SCEVExprsIdentical ? CommonSCEV : nullptr;
60566055
}

llvm/test/Analysis/ScalarEvolution/trip-count-phi-increment.ll

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
22
; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3-
define void @test(ptr %x, ptr %y) {
4-
; CHECK-LABEL: 'test'
5-
; CHECK-NEXT: Classifying expressions for: @test
3+
define void @test1(ptr %x, ptr %y) {
4+
; CHECK-LABEL: 'test1'
5+
; CHECK-NEXT: Classifying expressions for: @test1
66
; CHECK-NEXT: %v1.0 = phi i32 [ 0, %entry ], [ %k.0, %if.end ]
77
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.cond> U: [0,7) S: [0,7) Exits: 6 LoopDispositions: { %for.cond: Computable }
88
; CHECK-NEXT: %add = add nsw i32 %v1.0, 1
@@ -11,7 +11,7 @@ define void @test(ptr %x, ptr %y) {
1111
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable }
1212
; CHECK-NEXT: %k.0 = phi i32 [ %add, %if.then ], [ %add6, %if.else ]
1313
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable }
14-
; CHECK-NEXT: Determining loop execution counts for: @test
14+
; CHECK-NEXT: Determining loop execution counts for: @test1
1515
; CHECK-NEXT: Loop %for.cond: backedge-taken count is i32 6
1616
; CHECK-NEXT: Loop %for.cond: constant max backedge-taken count is i32 6
1717
; CHECK-NEXT: Loop %for.cond: symbolic max backedge-taken count is i32 6
@@ -44,3 +44,49 @@ if.end: ; preds = %4, %3
4444
exit: ; preds = %5
4545
ret void
4646
}
47+
48+
define void @test2(ptr %x, ptr %y) {
49+
; CHECK-LABEL: 'test2'
50+
; CHECK-NEXT: Classifying expressions for: @test2
51+
; CHECK-NEXT: %v1.0 = phi i32 [ 0, %entry ], [ %k.0, %if.end ]
52+
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.cond> U: [0,7) S: [0,7) Exits: 6 LoopDispositions: { %for.cond: Computable }
53+
; CHECK-NEXT: %add = add nuw i32 %v1.0, 1
54+
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable }
55+
; CHECK-NEXT: %add6 = add nsw i32 %v1.0, 1
56+
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable }
57+
; CHECK-NEXT: %k.0 = phi i32 [ %add, %if.then ], [ %add6, %if.else ]
58+
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable }
59+
; CHECK-NEXT: Determining loop execution counts for: @test2
60+
; CHECK-NEXT: Loop %for.cond: backedge-taken count is i32 6
61+
; CHECK-NEXT: Loop %for.cond: constant max backedge-taken count is i32 6
62+
; CHECK-NEXT: Loop %for.cond: symbolic max backedge-taken count is i32 6
63+
; CHECK-NEXT: Loop %for.cond: Trip multiple is 7
64+
;
65+
entry:
66+
br label %for.cond
67+
68+
for.cond: ; preds = %6, %0
69+
%v1.0 = phi i32 [ 0, %entry ], [ %k.0, %if.end ]
70+
%cmp = icmp slt i32 %v1.0, 6
71+
br i1 %cmp, label %for.body, label %exit
72+
73+
for.body: ; preds = %1
74+
%cmp3 = icmp slt i32 %v1.0, 2
75+
br i1 %cmp3, label %if.then, label %if.else
76+
77+
if.then: ; preds = %2
78+
%add = add nuw i32 %v1.0, 1
79+
br label %if.end
80+
81+
if.else: ; preds = %2
82+
%add6 = add nsw i32 %v1.0, 1
83+
br label %if.end
84+
85+
if.end: ; preds = %4, %3
86+
%k.0 = phi i32 [ %add, %if.then ], [ %add6, %if.else ]
87+
br label %for.cond
88+
89+
exit: ; preds = %5
90+
ret void
91+
}
92+

0 commit comments

Comments
 (0)