[llvm] d194646 - [NFC][SCEV] Improve/rework test coverage for ptrtoint handling

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 04:18:23 PDT 2020


Author: Roman Lebedev
Date: 2020-10-20T14:17:56+03:00
New Revision: d1946469d637f2e5245a02e908b630c3ca362717

URL: https://github.com/llvm/llvm-project/commit/d1946469d637f2e5245a02e908b630c3ca362717
DIFF: https://github.com/llvm/llvm-project/commit/d1946469d637f2e5245a02e908b630c3ca362717.diff

LOG: [NFC][SCEV] Improve/rework test coverage for ptrtoint handling

Added: 
    

Modified: 
    llvm/test/Analysis/ScalarEvolution/ptrtoint.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/ptrtoint.ll b/llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
index 1d32c5951e2a..313acf5aa301 100644
--- a/llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
+++ b/llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
@@ -157,31 +157,6 @@ define void @ptrtoint_of_inttoptr(i64 %in, i64* %out0) {
   ret void
 }
 
-; However, GEP is something SCEV knows how to model, so in this case ptrtoint
-; can't be modelled as a cast, only as an unknown.
-define void @ptrtoint_of_gep(i8* %in, i64* %out0) {
-; X64-LABEL: 'ptrtoint_of_gep'
-; X64-NEXT:  Classifying expressions for: @ptrtoint_of_gep
-; X64-NEXT:    %in_adj = getelementptr inbounds i8, i8* %in, i64 42
-; X64-NEXT:    --> (42 + %in)<nsw> U: [-9223372036854775766,-9223372036854775808) S: [-9223372036854775766,-9223372036854775808)
-; X64-NEXT:    %p0 = ptrtoint i8* %in_adj to i64
-; X64-NEXT:    --> %p0 U: full-set S: full-set
-; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_gep
-;
-; X32-LABEL: 'ptrtoint_of_gep'
-; X32-NEXT:  Classifying expressions for: @ptrtoint_of_gep
-; X32-NEXT:    %in_adj = getelementptr inbounds i8, i8* %in, i64 42
-; X32-NEXT:    --> (42 + %in)<nsw> U: [-2147483606,-2147483648) S: [-2147483606,-2147483648)
-; X32-NEXT:    %p0 = ptrtoint i8* %in_adj to i64
-; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
-; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_gep
-;
-  %in_adj = getelementptr inbounds i8, i8* %in, i64 42
-  %p0 = ptrtoint i8* %in_adj to i64
-  store i64  %p0, i64*  %out0
-  ret void
-}
-
 ; A constant pointer is fine
 define void @ptrtoint_of_nullptr(i64* %out0) {
 ; ALL-LABEL: 'ptrtoint_of_nullptr'
@@ -208,33 +183,184 @@ define void @ptrtoint_of_constantexpr_inttoptr(i64* %out0) {
   ret void
 }
 
-; However, while bitcast would be fine, GEP we can model, so we are back
-; to modelling the whole cast as unknown..
-define void @ptrtoint_of_bitcast_of_gep(i8* %in, i64* %out0) {
-; X64-LABEL: 'ptrtoint_of_bitcast_of_gep'
-; X64-NEXT:  Classifying expressions for: @ptrtoint_of_bitcast_of_gep
+; ptrtoint of GEP is fine.
+define void @ptrtoint_of_gep(i8* %in, i64* %out0) {
+; X64-LABEL: 'ptrtoint_of_gep'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_gep
 ; X64-NEXT:    %in_adj = getelementptr inbounds i8, i8* %in, i64 42
 ; X64-NEXT:    --> (42 + %in)<nsw> U: [-9223372036854775766,-9223372036854775808) S: [-9223372036854775766,-9223372036854775808)
-; X64-NEXT:    %in_adj_casted = bitcast i8* %in_adj to float*
-; X64-NEXT:    --> (42 + %in)<nsw> U: [-9223372036854775766,-9223372036854775808) S: [-9223372036854775766,-9223372036854775808)
-; X64-NEXT:    %p0 = ptrtoint float* %in_adj_casted to i64
+; X64-NEXT:    %p0 = ptrtoint i8* %in_adj to i64
 ; X64-NEXT:    --> %p0 U: full-set S: full-set
-; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_bitcast_of_gep
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_gep
 ;
-; X32-LABEL: 'ptrtoint_of_bitcast_of_gep'
-; X32-NEXT:  Classifying expressions for: @ptrtoint_of_bitcast_of_gep
+; X32-LABEL: 'ptrtoint_of_gep'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_gep
 ; X32-NEXT:    %in_adj = getelementptr inbounds i8, i8* %in, i64 42
 ; X32-NEXT:    --> (42 + %in)<nsw> U: [-2147483606,-2147483648) S: [-2147483606,-2147483648)
-; X32-NEXT:    %in_adj_casted = bitcast i8* %in_adj to float*
-; X32-NEXT:    --> (42 + %in)<nsw> U: [-2147483606,-2147483648) S: [-2147483606,-2147483648)
-; X32-NEXT:    %p0 = ptrtoint float* %in_adj_casted to i64
+; X32-NEXT:    %p0 = ptrtoint i8* %in_adj to i64
 ; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
-; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_bitcast_of_gep
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_gep
 ;
   %in_adj = getelementptr inbounds i8, i8* %in, i64 42
-  %in_adj_casted = bitcast i8* %in_adj to float*
-  %p0 = ptrtoint float* %in_adj_casted to i64
-  store i64 %p0, i64* %out0
+  %p0 = ptrtoint i8* %in_adj to i64
+  store i64  %p0, i64*  %out0
+  ret void
+}
+
+; It seems, we can't get ptrtoint of mul/udiv, or at least it's hard to come up with a test case.
+
+; ptrtoint of AddRec
+define void @ptrtoint_of_addrec(i32* %in, i32 %count) {
+; X64-LABEL: 'ptrtoint_of_addrec'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_addrec
+; X64-NEXT:    %i3 = zext i32 %count to i64
+; X64-NEXT:    --> (zext i32 %count to i64) U: [0,4294967296) S: [0,4294967296)
+; X64-NEXT:    %i6 = phi i64 [ 0, %entry ], [ %i9, %loop ]
+; X64-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: (-1 + (zext i32 %count to i64))<nsw> LoopDispositions: { %loop: Computable }
+; X64-NEXT:    %i7 = getelementptr inbounds i32, i32* %in, i64 %i6
+; X64-NEXT:    --> {%in,+,4}<nsw><%loop> U: full-set S: full-set Exits: (-4 + (4 * (zext i32 %count to i64))<nuw><nsw> + %in) LoopDispositions: { %loop: Computable }
+; X64-NEXT:    %i8 = ptrtoint i32* %i7 to i64
+; X64-NEXT:    --> %i8 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; X64-NEXT:    %i9 = add nuw nsw i64 %i6, 1
+; X64-NEXT:    --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: (zext i32 %count to i64) LoopDispositions: { %loop: Computable }
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_addrec
+; X64-NEXT:  Loop %loop: backedge-taken count is (-1 + (zext i32 %count to i64))<nsw>
+; X64-NEXT:  Loop %loop: max backedge-taken count is -1
+; X64-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + (zext i32 %count to i64))<nsw>
+; X64-NEXT:   Predicates:
+; X64:       Loop %loop: Trip multiple is 1
+;
+; X32-LABEL: 'ptrtoint_of_addrec'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_addrec
+; X32-NEXT:    %i3 = zext i32 %count to i64
+; X32-NEXT:    --> (zext i32 %count to i64) U: [0,4294967296) S: [0,4294967296)
+; X32-NEXT:    %i6 = phi i64 [ 0, %entry ], [ %i9, %loop ]
+; X32-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,-9223372036854775808) S: [0,-9223372036854775808) Exits: (-1 + (zext i32 %count to i64))<nsw> LoopDispositions: { %loop: Computable }
+; X32-NEXT:    %i7 = getelementptr inbounds i32, i32* %in, i64 %i6
+; X32-NEXT:    --> {%in,+,4}<%loop> U: full-set S: full-set Exits: (-4 + (4 * %count) + %in) LoopDispositions: { %loop: Computable }
+; X32-NEXT:    %i8 = ptrtoint i32* %i7 to i64
+; X32-NEXT:    --> %i8 U: [0,4294967296) S: [-4294967296,4294967296) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; X32-NEXT:    %i9 = add nuw nsw i64 %i6, 1
+; X32-NEXT:    --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: (zext i32 %count to i64) LoopDispositions: { %loop: Computable }
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_addrec
+; X32-NEXT:  Loop %loop: backedge-taken count is (-1 + (zext i32 %count to i64))<nsw>
+; X32-NEXT:  Loop %loop: max backedge-taken count is -1
+; X32-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + (zext i32 %count to i64))<nsw>
+; X32-NEXT:   Predicates:
+; X32:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %i3 = zext i32 %count to i64
+  br label %loop
+
+loop:
+  %i6 = phi i64 [ 0, %entry ], [ %i9, %loop ]
+  %i7 = getelementptr inbounds i32, i32* %in, i64 %i6
+  %i8 = ptrtoint i32* %i7 to i64
+  tail call void @use(i64 %i8)
+  %i9 = add nuw nsw i64 %i6, 1
+  %i10 = icmp eq i64 %i9, %i3
+  br i1 %i10, label %end, label %loop
+
+end:
+  ret void
+}
+declare void @use(i64)
+
+; ptrtoint of UMax
+define void @ptrtoint_of_umax(i8* %in0, i8* %in1, i64* %out0) {
+; X64-LABEL: 'ptrtoint_of_umax'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_umax
+; X64-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X64-NEXT:    --> (%in0 umax %in1) U: full-set S: full-set
+; X64-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X64-NEXT:    --> %p0 U: full-set S: full-set
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_umax
+;
+; X32-LABEL: 'ptrtoint_of_umax'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_umax
+; X32-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X32-NEXT:    --> (%in0 umax %in1) U: full-set S: full-set
+; X32-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_umax
+;
+  %c = icmp uge i8* %in0, %in1
+  %s = select i1 %c, i8* %in0, i8* %in1
+  %p0 = ptrtoint i8* %s to i64
+  store i64  %p0, i64*  %out0
+  ret void
+}
+; ptrtoint of SMax
+define void @ptrtoint_of_smax(i8* %in0, i8* %in1, i64* %out0) {
+; X64-LABEL: 'ptrtoint_of_smax'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_smax
+; X64-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X64-NEXT:    --> (%in0 smax %in1) U: full-set S: full-set
+; X64-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X64-NEXT:    --> %p0 U: full-set S: full-set
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_smax
+;
+; X32-LABEL: 'ptrtoint_of_smax'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_smax
+; X32-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X32-NEXT:    --> (%in0 smax %in1) U: full-set S: full-set
+; X32-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_smax
+;
+  %c = icmp sge i8* %in0, %in1
+  %s = select i1 %c, i8* %in0, i8* %in1
+  %p0 = ptrtoint i8* %s to i64
+  store i64  %p0, i64*  %out0
+  ret void
+}
+; ptrtoint of UMin
+define void @ptrtoint_of_umin(i8* %in0, i8* %in1, i64* %out0) {
+; X64-LABEL: 'ptrtoint_of_umin'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_umin
+; X64-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X64-NEXT:    --> (%in0 umin %in1) U: full-set S: full-set
+; X64-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X64-NEXT:    --> %p0 U: full-set S: full-set
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_umin
+;
+; X32-LABEL: 'ptrtoint_of_umin'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_umin
+; X32-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X32-NEXT:    --> (%in0 umin %in1) U: full-set S: full-set
+; X32-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_umin
+;
+  %c = icmp ule i8* %in0, %in1
+  %s = select i1 %c, i8* %in0, i8* %in1
+  %p0 = ptrtoint i8* %s to i64
+  store i64  %p0, i64*  %out0
+  ret void
+}
+; ptrtoint of SMin
+define void @ptrtoint_of_smin(i8* %in0, i8* %in1, i64* %out0) {
+; X64-LABEL: 'ptrtoint_of_smin'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_smin
+; X64-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X64-NEXT:    --> (%in0 smin %in1) U: full-set S: full-set
+; X64-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X64-NEXT:    --> %p0 U: full-set S: full-set
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_smin
+;
+; X32-LABEL: 'ptrtoint_of_smin'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_smin
+; X32-NEXT:    %s = select i1 %c, i8* %in0, i8* %in1
+; X32-NEXT:    --> (%in0 smin %in1) U: full-set S: full-set
+; X32-NEXT:    %p0 = ptrtoint i8* %s to i64
+; X32-NEXT:    --> %p0 U: [0,4294967296) S: [-4294967296,4294967296)
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_smin
+;
+  %c = icmp sle i8* %in0, %in1
+  %s = select i1 %c, i8* %in0, i8* %in1
+  %p0 = ptrtoint i8* %s to i64
+  store i64  %p0, i64*  %out0
   ret void
 }
 
@@ -410,3 +536,71 @@ bb6:
 bb5:
   ret void
 }
+
+; During SCEV rewrites, we could end up calling `ScalarEvolution::getPtrToIntExpr()`
+; on an integer. Make sure we handle that case gracefully.
+define void @ptrtoint_of_integer(i8* %arg, i64 %arg1, i1 %arg2) local_unnamed_addr {
+; X64-LABEL: 'ptrtoint_of_integer'
+; X64-NEXT:  Classifying expressions for: @ptrtoint_of_integer
+; X64-NEXT:    %i4 = ptrtoint i8* %arg to i64
+; X64-NEXT:    --> %i4 U: full-set S: full-set
+; X64-NEXT:    %i6 = sub i64 %i4, %arg1
+; X64-NEXT:    --> ((-1 * %arg1) + %i4) U: full-set S: full-set
+; X64-NEXT:    %i9 = phi i64 [ 1, %bb7 ], [ %i11, %bb10 ]
+; X64-NEXT:    --> {1,+,1}<nuw><%bb8> U: [1,0) S: [1,0) Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
+; X64-NEXT:    %i11 = add nuw i64 %i9, 1
+; X64-NEXT:    --> {2,+,1}<nw><%bb8> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
+; X64-NEXT:  Determining loop execution counts for: @ptrtoint_of_integer
+; X64-NEXT:  Loop %bb8: <multiple exits> Unpredictable backedge-taken count.
+; X64-NEXT:    exit count for bb8: ***COULDNOTCOMPUTE***
+; X64-NEXT:    exit count for bb10: (-2 + (-1 * %arg1) + %i4)
+; X64-NEXT:  Loop %bb8: max backedge-taken count is -1
+; X64-NEXT:  Loop %bb8: Unpredictable predicated backedge-taken count.
+;
+; X32-LABEL: 'ptrtoint_of_integer'
+; X32-NEXT:  Classifying expressions for: @ptrtoint_of_integer
+; X32-NEXT:    %i4 = ptrtoint i8* %arg to i64
+; X32-NEXT:    --> %i4 U: [0,4294967296) S: [-4294967296,4294967296)
+; X32-NEXT:    %i6 = sub i64 %i4, %arg1
+; X32-NEXT:    --> ((-1 * %arg1) + %i4) U: full-set S: full-set
+; X32-NEXT:    %i9 = phi i64 [ 1, %bb7 ], [ %i11, %bb10 ]
+; X32-NEXT:    --> {1,+,1}<nuw><%bb8> U: [1,0) S: [1,0) Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
+; X32-NEXT:    %i11 = add nuw i64 %i9, 1
+; X32-NEXT:    --> {2,+,1}<nw><%bb8> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
+; X32-NEXT:  Determining loop execution counts for: @ptrtoint_of_integer
+; X32-NEXT:  Loop %bb8: <multiple exits> Unpredictable backedge-taken count.
+; X32-NEXT:    exit count for bb8: ***COULDNOTCOMPUTE***
+; X32-NEXT:    exit count for bb10: (-2 + (-1 * %arg1) + %i4)
+; X32-NEXT:  Loop %bb8: max backedge-taken count is -1
+; X32-NEXT:  Loop %bb8: Unpredictable predicated backedge-taken count.
+;
+bb:
+  %i = icmp eq i8* %arg, null
+  br i1 %i, label %bb14, label %bb3
+
+bb3:                                              ; preds = %bb
+  %i4 = ptrtoint i8* %arg to i64
+  br label %bb5
+
+bb5:                                              ; preds = %bb3
+  %i6 = sub i64 %i4, %arg1
+  br label %bb7
+
+bb7:                                              ; preds = %bb5
+  br label %bb8
+
+bb8:                                              ; preds = %bb10, %bb7
+  %i9 = phi i64 [ 1, %bb7 ], [ %i11, %bb10 ]
+  br i1 %arg2, label %bb10, label %bb13
+
+bb10:                                             ; preds = %bb8
+  %i11 = add nuw i64 %i9, 1
+  %i12 = icmp eq i64 %i11, %i6
+  br i1 %i12, label %bb13, label %bb8
+
+bb13:                                             ; preds = %bb10, %bb8
+  ret void
+
+bb14:                                             ; preds = %bb
+  ret void
+}


        


More information about the llvm-commits mailing list