[llvm] b24b6c4 - [PhaseOrdering] Add test with gep null compare in loop (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 29 01:19:36 PDT 2023
Author: Arthur Eubanks
Date: 2023-06-29T10:19:28+02:00
New Revision: b24b6c4a32e159ece79583b3aaf5887ea44c4ebf
URL: https://github.com/llvm/llvm-project/commit/b24b6c4a32e159ece79583b3aaf5887ea44c4ebf
DIFF: https://github.com/llvm/llvm-project/commit/b24b6c4a32e159ece79583b3aaf5887ea44c4ebf.diff
LOG: [PhaseOrdering] Add test with gep null compare in loop (NFC)
Test from D153392 in both the alloca and malloc variants.
Added:
llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll b/llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
new file mode 100644
index 00000000000000..29b1717bffeacb
--- /dev/null
+++ b/llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
@@ -0,0 +1,92 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+
+; RUN: opt -O3 -S < %s | FileCheck %s
+
+define internal i32 @loop(ptr %arg, ptr %arg1) {
+bb:
+ br label %bb2
+
+bb2:
+ %phi = phi ptr [ %arg, %bb ], [ %phi8, %bb11 ]
+ %phi3 = phi i32 [ 0, %bb ], [ %add, %bb11 ]
+ %icmp = icmp ne ptr %arg1, null
+ %icmp4 = icmp eq ptr %phi, %arg1
+ br i1 %icmp4, label %bb7, label %bb5
+
+bb5:
+ %getelementptr = getelementptr inbounds i32, ptr %phi, i64 1
+ br label %bb7
+
+bb7:
+ %phi8 = phi ptr [ %phi, %bb2 ], [ %getelementptr, %bb5 ]
+ %phi9 = phi ptr [ null, %bb2 ], [ %phi, %bb5 ]
+ %icmp10 = icmp eq ptr %phi9, null
+ br i1 %icmp10, label %bb12, label %bb11
+
+bb11:
+ %load = load i32, ptr %phi9, align 4
+ %add = add i32 %load, %phi3
+ br label %bb2
+
+bb12:
+ ret i32 %phi3
+}
+
+define i32 @using_alloca() {
+; CHECK-LABEL: define i32 @using_alloca
+; CHECK-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: bb:
+; CHECK-NEXT: ret i32 6
+;
+bb:
+ %alloca = alloca [3 x i32], align 4
+ store i32 1, ptr %alloca, align 4
+ %getelementptr = getelementptr i32, ptr %alloca, i32 1
+ store i32 2, ptr %getelementptr, align 4
+ %getelementptr1 = getelementptr i32, ptr %alloca, i32 2
+ store i32 3, ptr %getelementptr1, align 4
+ %getelementptr2 = getelementptr i32, ptr %alloca, i32 3
+ %call = call i32 @loop(ptr %alloca, ptr %getelementptr2)
+ ret i32 %call
+}
+
+define i32 @using_malloc() {
+; CHECK-LABEL: define i32 @using_malloc
+; CHECK-SAME: () local_unnamed_addr #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT: bb:
+; CHECK-NEXT: [[ALLOC:%.*]] = tail call dereferenceable_or_null(64) ptr @malloc(i64 64)
+; CHECK-NEXT: store i32 1, ptr [[ALLOC]], align 4
+; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 1
+; CHECK-NEXT: store i32 2, ptr [[GETELEMENTPTR]], align 4
+; CHECK-NEXT: [[GETELEMENTPTR1:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 2
+; CHECK-NEXT: store i32 3, ptr [[GETELEMENTPTR1]], align 4
+; CHECK-NEXT: [[GETELEMENTPTR2:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 3
+; CHECK-NEXT: br label [[BB11_I:%.*]]
+; CHECK: bb11.i:
+; CHECK-NEXT: [[PHI37_I:%.*]] = phi i32 [ [[ADD_I:%.*]], [[BB11_I]] ], [ 0, [[BB:%.*]] ]
+; CHECK-NEXT: [[PHI6_I:%.*]] = phi ptr [ [[SPEC_SELECT_I:%.*]], [[BB11_I]] ], [ [[ALLOC]], [[BB]] ]
+; CHECK-NEXT: [[SPEC_SELECT_I]] = getelementptr i32, ptr [[PHI6_I]], i64 1
+; CHECK-NEXT: [[LOAD_I:%.*]] = load i32, ptr [[PHI6_I]], align 4
+; CHECK-NEXT: [[ADD_I]] = add i32 [[LOAD_I]], [[PHI37_I]]
+; CHECK-NEXT: [[ICMP4_I:%.*]] = icmp ne ptr [[SPEC_SELECT_I]], [[GETELEMENTPTR2]]
+; CHECK-NEXT: [[ICMP102_I:%.*]] = icmp ne ptr [[SPEC_SELECT_I]], null
+; CHECK-NEXT: [[ICMP10_NOT_I:%.*]] = and i1 [[ICMP102_I]], [[ICMP4_I]]
+; CHECK-NEXT: br i1 [[ICMP10_NOT_I]], label [[BB11_I]], label [[LOOP_EXIT:%.*]]
+; CHECK: loop.exit:
+; CHECK-NEXT: ret i32 [[ADD_I]]
+;
+bb:
+ %alloc = call dereferenceable_or_null(64) ptr @malloc(i64 64)
+ store i32 1, ptr %alloc, align 4
+ %getelementptr = getelementptr i32, ptr %alloc, i64 1
+ store i32 2, ptr %getelementptr, align 4
+ %getelementptr1 = getelementptr i32, ptr %alloc, i64 2
+ store i32 3, ptr %getelementptr1, align 4
+ %getelementptr2 = getelementptr i32, ptr %alloc, i64 3
+ %call = call i32 @loop(ptr %alloc, ptr %getelementptr2)
+ ret i32 %call
+}
+
+declare ptr @malloc(i64)
+
+declare void @free(ptr)
More information about the llvm-commits
mailing list