-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[SCEV] Simplify SCEVExpr for PHI to SCEV for operand if operands are identical #115945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ff9c1b8
24e4262
bd8642d
7c43e64
231503f
ea17ced
68c8213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6019,6 +6019,37 @@ const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) { | |
| return nullptr; | ||
| } | ||
|
|
||
| // Returns SCEV for the first operand of a phi if all phi operands have | ||
akshayrdeodhar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // identical opcodes and operands | ||
| // eg. | ||
| // a: %add = %a + %b | ||
| // br %c | ||
| // b: %add1 = %a + %b | ||
| // br %c | ||
| // c: %phi = phi [%add, a], [%add1, b] | ||
| // scev(%phi) => scev(%add) | ||
| const SCEV * | ||
| ScalarEvolution::createNodeForPHIWithIdenticalOperands(PHINode *PN) { | ||
| BinaryOperator *CommonInst = nullptr; | ||
| for (Value *Incoming : PN->incoming_values()) { | ||
| BinaryOperator *IncomingInst = dyn_cast<BinaryOperator>(Incoming); | ||
akshayrdeodhar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (CommonInst) { | ||
| if (!(IncomingInst && CommonInst->isIdenticalTo(IncomingInst))) { | ||
|
||
| // Not identical, give up | ||
| CommonInst = nullptr; | ||
| break; | ||
akshayrdeodhar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } else if (IncomingInst) { | ||
| // Remember binary operator | ||
| CommonInst = IncomingInst; | ||
| } else { | ||
| // Not a binary operator, give up | ||
akshayrdeodhar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nullptr; | ||
| } | ||
| } | ||
| return CommonInst ? getSCEV(CommonInst) : nullptr; | ||
|
||
| } | ||
|
|
||
| const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { | ||
| if (const SCEV *S = createAddRecFromPHI(PN)) | ||
| return S; | ||
|
|
@@ -6030,6 +6061,9 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { | |
| /*UseInstrInfo=*/true, /*CanUseUndef=*/false})) | ||
| return getSCEV(V); | ||
|
|
||
| if (const SCEV *S = createNodeForPHIWithIdenticalOperands(PN)) | ||
| return S; | ||
|
|
||
| if (const SCEV *S = createNodeFromSelectLikePHI(PN)) | ||
| return S; | ||
|
|
||
|
|
||
akshayrdeodhar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s | ||
| define void @test(ptr %x, ptr %y) { | ||
| ; CHECK-LABEL: 'test' | ||
| ; CHECK-NEXT: Classifying expressions for: @test | ||
| ; CHECK-NEXT: %v1.0 = phi i32 [ 0, %entry ], [ %k.0, %if.end ] | ||
| ; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.cond> U: [0,7) S: [0,7) Exits: 6 LoopDispositions: { %for.cond: Computable } | ||
| ; CHECK-NEXT: %add = add nsw i32 %v1.0, 1 | ||
| ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable } | ||
| ; CHECK-NEXT: %add6 = add nsw i32 %v1.0, 1 | ||
| ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable } | ||
| ; CHECK-NEXT: %k.0 = phi i32 [ %add, %if.then ], [ %add6, %if.else ] | ||
| ; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%for.cond> U: [1,8) S: [1,8) Exits: 7 LoopDispositions: { %for.cond: Computable } | ||
| ; CHECK-NEXT: Determining loop execution counts for: @test | ||
| ; CHECK-NEXT: Loop %for.cond: backedge-taken count is i32 6 | ||
| ; CHECK-NEXT: Loop %for.cond: constant max backedge-taken count is i32 6 | ||
| ; CHECK-NEXT: Loop %for.cond: symbolic max backedge-taken count is i32 6 | ||
| ; CHECK-NEXT: Loop %for.cond: Trip multiple is 7 | ||
| ; | ||
| entry: | ||
| br label %for.cond | ||
|
|
||
| for.cond: ; preds = %6, %0 | ||
| %v1.0 = phi i32 [ 0, %entry ], [ %k.0, %if.end ] | ||
| %cmp = icmp slt i32 %v1.0, 6 | ||
| br i1 %cmp, label %for.body, label %exit | ||
|
|
||
| for.body: ; preds = %1 | ||
| %cmp3 = icmp slt i32 %v1.0, 2 | ||
| br i1 %cmp3, label %if.then, label %if.else | ||
|
|
||
| if.then: ; preds = %2 | ||
| %add = add nsw i32 %v1.0, 1 | ||
| br label %if.end | ||
|
|
||
| if.else: ; preds = %2 | ||
| %add6 = add nsw i32 %v1.0, 1 | ||
| br label %if.end | ||
|
|
||
| if.end: ; preds = %4, %3 | ||
| %k.0 = phi i32 [ %add, %if.then ], [ %add6, %if.else ] | ||
| br label %for.cond | ||
|
|
||
| exit: ; preds = %5 | ||
| ret void | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.