[PATCH] D57568: [SCEV] Optimize getting SCEV of one-input Phis

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 1 00:00:57 PST 2019


mkazantsev created this revision.
mkazantsev added reviewers: sanjoy, anna, skatkov, reames.
Herald added a subscriber: javed.absar.

Phis that have only one input are by all means equivalent to their input.
So their SCEVs should also match. In practice, SCEV often ends up creating
SCEVUnknown nodes for them, which makes no sense. It is a frequently
occurring across the optimizer since one-input Phi are used for LCSSA form.


https://reviews.llvm.org/D57568

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Analysis/ScalarEvolution/solve-quadratic-i1.ll
  test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll
  test/Transforms/LoopStrengthReduce/funclet.ll


Index: test/Transforms/LoopStrengthReduce/funclet.ll
===================================================================
--- test/Transforms/LoopStrengthReduce/funclet.ll
+++ test/Transforms/LoopStrengthReduce/funclet.ll
@@ -45,7 +45,7 @@
 
 ; CHECK-LABEL: define void @f(
 ; CHECK: cleanuppad within none []
-; CHECK-NEXT: ptrtoint i8* %phi2 to i32
+; CHECK-NEXT: br
 
 define void @g() personality i32 (...)* @_except_handler3 {
 entry:
@@ -87,7 +87,7 @@
 ; CHECK-LABEL: define void @g(
 ; CHECK: blah:
 ; CHECK-NEXT: catchpad within %cs []
-; CHECK-NEXT: ptrtoint i8* %phi2 to i32
+; CHECK-NEXT: br
 
 
 define void @h() personality i32 (...)* @_except_handler3 {
@@ -130,7 +130,7 @@
 ; CHECK-LABEL: define void @h(
 ; CHECK: blug:
 ; CHECK: catchpad within %cs []
-; CHECK-NEXT: ptrtoint i8* %phi2 to i32
+; CHECK-NEXT: br
 
 define void @i() personality i32 (...)* @_except_handler3 {
 entry:
@@ -170,7 +170,7 @@
 }
 
 ; CHECK-LABEL: define void @i(
-; CHECK: ptrtoint i8* %phi2 to i32
+; CHECK-NOT: ptrtoint i8* %phi2 to i32
 
 define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
 entry:
Index: test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll
===================================================================
--- test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll
+++ test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll
@@ -12,11 +12,11 @@
 ; CHECK-NEXT:   %v3 = mul i16 %v2, %v2
 ; CHECK-NEXT:   -->  {1,+,3,+,2}<%b1> U: full-set S: full-set         Exits: 0               LoopDispositions: { %b1: Computable }
 ; CHECK-NEXT:   %v5 = phi i16 [ %v2, %b1 ]
-; CHECK-NEXT:   -->  %v5 U: [-256,0) S: [-256,0)
+; CHECK-NEXT:   --> {-1,+,-1}<%b1> U: [-256,0) S: [-256,0)
 ; CHECK-NEXT:   %v6 = phi i16 [ %v3, %b1 ]
-; CHECK-NEXT:   -->  %v6 U: full-set S: full-set
+; CHECK-NEXT:   --> {1,+,3,+,2}<%b1> U: full-set S: full-set
 ; CHECK-NEXT:   %v7 = sext i16 %v5 to i32
-; CHECK-NEXT:   -->  (sext i16 %v5 to i32) U: [-256,0) S: [-256,0)
+; CHECK-NEXT:   --> {-1,+,-1}<nsw><%b1> U: [-256,0) S: [-256,0)
 ; CHECK-NEXT: Determining loop execution counts for: @f0
 ; CHECK-NEXT: Loop %b1: backedge-taken count is 255
 ; CHECK-NEXT: Loop %b1: max backedge-taken count is 255
Index: test/Analysis/ScalarEvolution/solve-quadratic-i1.ll
===================================================================
--- test/Analysis/ScalarEvolution/solve-quadratic-i1.ll
+++ test/Analysis/ScalarEvolution/solve-quadratic-i1.ll
@@ -57,9 +57,9 @@
 ; CHECK-NEXT:   %v6 = add nuw nsw i32 %v1, 1
 ; CHECK-NEXT:   -->  {4,+,1}<nuw><nsw><%b1> U: [4,7) S: [4,7)         Exits: 6                LoopDispositions: { %b1: Computable }
 ; CHECK-NEXT:   %v7 = phi i32 [ %v1, %b1 ]
-; CHECK-NEXT:   -->  %v7 U: [3,6) S: [3,6)
+; CHECK-NEXT:   --> {3,+,1}<nuw><nsw><%b1> U: [3,6) S: [3,6)
 ; CHECK-NEXT:   %v8 = phi i16 [ %v3, %b1 ]
-; CHECK-NEXT:   -->  %v8 U: full-set S: full-set
+; CHECK-NEXT:   --> {3,+,4,+,1}<%b1> U: full-set S: full-set
 ; CHECK-NEXT: Determining loop execution counts for: @f1
 ; CHECK-NEXT: Loop %b3: <multiple exits> Unpredictable backedge-taken count.
 ; CHECK-NEXT: Loop %b3: Unpredictable max backedge-taken count.
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -5333,6 +5333,9 @@
 }
 
 const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {
+  if (PN->getNumOperands() == 1)
+    return getSCEV(PN->getOperand(0));
+
   if (const SCEV *S = createAddRecFromPHI(PN))
     return S;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57568.184687.patch
Type: text/x-patch
Size: 3582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190201/8e7ff031/attachment.bin>


More information about the llvm-commits mailing list