[llvm] f3c664e - [LoopVersioning] Add test case with foldable icmp in runtime check.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 14 05:42:37 PST 2022


Author: Florian Hahn
Date: 2022-01-14T13:42:20Z
New Revision: f3c664e5de4e7ddc04c3b54b14c2b234616dcd1a

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

LOG: [LoopVersioning] Add test case with foldable icmp in runtime check.

Test case showing a foldable icmp ('icmp ult i8* [[SCEVGEP1]], [[SCEVGEP1]]').
This can be simplified in a follow-up change.

Added: 
    llvm/test/Transforms/LoopVersioning/bound-check-partially-known.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopVersioning/bound-check-partially-known.ll b/llvm/test/Transforms/LoopVersioning/bound-check-partially-known.ll
new file mode 100644
index 000000000000..7c390d347383
--- /dev/null
+++ b/llvm/test/Transforms/LoopVersioning/bound-check-partially-known.ll
@@ -0,0 +1,48 @@
+; RUN: opt -aa-pipeline=basic-aa -passes=loop-versioning -S %s | FileCheck %s
+
+%struct.foo = type { [32000 x double], [32000 x double] }
+
+ at global = external global %struct.foo, align 32
+
+define void @bound_check_partially_known_1(i32 %N) {
+; CHECK-LABEL: @bound_check_partially_known_1(
+; CHECK-NEXT:  loop.lver.check:
+; CHECK-NEXT:    [[N_EXT:%.*]] = zext i32 [[N:%.*]] to i64
+; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[STRUCT_FOO:%.*]], %struct.foo* @global, i64 0, i32 0, i64 [[N_EXT]]
+; CHECK-NEXT:    [[SCEVGEP1:%.*]] = bitcast double* [[SCEVGEP]] to i8*
+; CHECK-NEXT:    [[TMP0:%.*]] = shl nuw nsw i64 [[N_EXT]], 1
+; CHECK-NEXT:    [[SCEVGEP2:%.*]] = getelementptr [[STRUCT_FOO]], %struct.foo* @global, i64 0, i32 0, i64 [[TMP0]]
+; CHECK-NEXT:    [[SCEVGEP23:%.*]] = bitcast double* [[SCEVGEP2]] to i8*
+; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i64 [[N_EXT]], 32000
+; CHECK-NEXT:    [[SCEVGEP4:%.*]] = getelementptr [[STRUCT_FOO]], %struct.foo* @global, i64 0, i32 0, i64 [[TMP1]]
+; CHECK-NEXT:    [[SCEVGEP45:%.*]] = bitcast double* [[SCEVGEP4]] to i8*
+; CHECK-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP1]]
+; CHECK-NEXT:    [[BOUND1:%.*]] = icmp ult i8* bitcast (%struct.foo* @global to i8*), [[SCEVGEP23]]
+; CHECK-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
+; CHECK-NEXT:    [[BOUND06:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP45]]
+; CHECK-NEXT:    [[BOUND17:%.*]] = icmp ult i8* bitcast (double* getelementptr inbounds ([[STRUCT_FOO]], %struct.foo* @global, i64 0, i32 1, i64 0) to i8*), [[SCEVGEP23]]
+; CHECK-NEXT:    [[FOUND_CONFLICT8:%.*]] = and i1 [[BOUND06]], [[BOUND17]]
+; CHECK-NEXT:    [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT8]]
+; CHECK-NEXT:    br i1 [[CONFLICT_RDX]], label %loop.ph.lver.orig, label %loop.ph
+;
+entry:
+  %N.ext = zext i32 %N to i64
+  br label %loop
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  %gep.0.iv = getelementptr inbounds %struct.foo, %struct.foo* @global, i64 0, i32 0, i64 %iv
+  %l.0 = load double, double* %gep.0.iv, align 8
+  %gep.1.iv = getelementptr inbounds %struct.foo, %struct.foo* @global, i64 0, i32 1, i64 %iv
+  %l.1 = load double, double* %gep.1.iv, align 8
+  %add = fadd double %l.0, %l.1
+  %iv.N = add nuw nsw i64 %iv, %N.ext
+  %gep.0.iv.N = getelementptr inbounds %struct.foo, %struct.foo* @global, i64 0, i32 0, i64 %iv.N
+  store double %add, double* %gep.0.iv.N, align 8
+  %iv.next = add nuw nsw i64 %iv, 1
+  %exitcond = icmp eq i64 %iv.next, %N.ext
+  br i1 %exitcond, label %exit, label %loop
+
+exit:
+  ret void
+}


        


More information about the llvm-commits mailing list