[llvm] 06ade34 - [InstCombine] Add multi-use tests for gep of gep fold (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 03:47:02 PST 2023
Author: Nikita Popov
Date: 2023-01-20T12:46:54+01:00
New Revision: 06ade34c4bf8378f960b7e7564f1ba2316f6a990
URL: https://github.com/llvm/llvm-project/commit/06ade34c4bf8378f960b7e7564f1ba2316f6a990
DIFF: https://github.com/llvm/llvm-project/commit/06ade34c4bf8378f960b7e7564f1ba2316f6a990.diff
LOG: [InstCombine] Add multi-use tests for gep of gep fold (NFC)
Added:
Modified:
llvm/test/Transforms/InstCombine/getelementptr.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll
index 0f8c70f8d458..8366decfcbbe 100644
--- a/llvm/test/Transforms/InstCombine/getelementptr.ll
+++ b/llvm/test/Transforms/InstCombine/getelementptr.ll
@@ -13,6 +13,8 @@ target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64"
@Global = external global [10 x i8]
@Global_as1 = external addrspace(1) global [10 x i8]
+declare void @use(ptr)
+
; Test noop elimination
define ptr @test1(ptr %I) {
; CHECK-LABEL: @test1(
@@ -1266,4 +1268,43 @@ entry:
ret i32 %a_c
}
+define ptr @gep_of_gep_multiuse_const_and_const(ptr %p, i64 %idx) {
+; CHECK-LABEL: @gep_of_gep_multiuse_const_and_const(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr { i32, i32 }, ptr [[P:%.*]], i64 1
+; CHECK-NEXT: call void @use(ptr [[GEP1]])
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr { i32, i32 }, ptr [[P]], i64 1, i32 1
+; CHECK-NEXT: ret ptr [[GEP2]]
+;
+ %gep1 = getelementptr { i32, i32 }, ptr %p, i64 1
+ call void @use(ptr %gep1)
+ %gep2 = getelementptr { i32, i32 }, ptr %gep1, i64 0, i32 1
+ ret ptr %gep2
+}
+
+define ptr @gep_of_gep_multiuse_var_and_const(ptr %p, i64 %idx) {
+; CHECK-LABEL: @gep_of_gep_multiuse_var_and_const(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr { i32, i32 }, ptr [[P:%.*]], i64 [[IDX:%.*]]
+; CHECK-NEXT: call void @use(ptr [[GEP1]])
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr { i32, i32 }, ptr [[P]], i64 [[IDX]], i32 1
+; CHECK-NEXT: ret ptr [[GEP2]]
+;
+ %gep1 = getelementptr { i32, i32 }, ptr %p, i64 %idx
+ call void @use(ptr %gep1)
+ %gep2 = getelementptr { i32, i32 }, ptr %gep1, i64 0, i32 1
+ ret ptr %gep2
+}
+
+define ptr @gep_of_gep_multiuse_var_and_var(ptr %p, i64 %idx, i64 %idx2) {
+; CHECK-LABEL: @gep_of_gep_multiuse_var_and_var(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr [4 x i32], ptr [[P:%.*]], i64 [[IDX:%.*]]
+; CHECK-NEXT: call void @use(ptr [[GEP1]])
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr [4 x i32], ptr [[P]], i64 [[IDX]], i64 [[IDX2:%.*]]
+; CHECK-NEXT: ret ptr [[GEP2]]
+;
+ %gep1 = getelementptr [4 x i32], ptr %p, i64 %idx
+ call void @use(ptr %gep1)
+ %gep2 = getelementptr [4 x i32], ptr %gep1, i64 0, i64 %idx2
+ ret ptr %gep2
+}
+
!0 = !{!"branch_weights", i32 2, i32 10}
More information about the llvm-commits
mailing list