[llvm] 2d279c0 - [llvm] Add tests for upcoming fixes to pointer/index type confusion.

Krzysztof Drewniak via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 7 08:07:03 PST 2023


Author: Krzysztof Drewniak
Date: 2023-02-07T16:06:58Z
New Revision: 2d279c0d95d405098a6148cad6c9a68c92e6df4f

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

LOG: [llvm] Add tests for upcoming fixes to pointer/index type confusion.

Various parts of the codebase are using getIntPtrType() and its
relatives when getting the type of the offset argument to GEP. Most
such code has been updated to use the pointer index type field from
the data layout, but there is code that still assumes these two types
are the same in certain optimizaiton passes.

This commit adds regression tests to capture the old behavior.

Reviewed By: #amdgpu, arsenm

Differential Revision: https://reviews.llvm.org/D143435

Added: 
    llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll
    llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll b/llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll
new file mode 100644
index 0000000000000..437e26fee3f9e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+target datalayout = "p0:64:64:64-p7:128:128:128:32-A7"
+
+define void @test_array_alloca_intptr_not_sizet(i64 %size, ptr %dest) {
+; CHECK-LABEL: @test_array_alloca_intptr_not_sizet(
+; CHECK-NEXT:    [[TMP1:%.*]] = zext i64 [[SIZE:%.*]] to i128
+; CHECK-NEXT:    [[ALLOCA:%.*]] = alloca i8, i128 [[TMP1]], align 1, addrspace(7)
+; CHECK-NEXT:    store ptr addrspace(7) [[ALLOCA]], ptr [[DEST:%.*]], align 16
+; CHECK-NEXT:    ret void
+;
+  %alloca = alloca i8, i64 %size, addrspace(7)
+  store ptr addrspace(7) %alloca, ptr %dest
+  ret void
+}

diff  --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll
new file mode 100644
index 0000000000000..f2264af7261af
--- /dev/null
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=separate-const-offset-from-gep -S | FileCheck %s
+target datalayout = "p0:64:64:64-p1:128:128:128:32"
+
+define void @should_be_trunc(ptr addrspace(1) %ptr,  i64 %index, ptr %result) {
+; CHECK-LABEL: @should_be_trunc(
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i64 [[INDEX:%.*]] to i128
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr ptr addrspace(1), ptr addrspace(1) [[PTR:%.*]], i128 [[IDXPROM]]
+; CHECK-NEXT:    store ptr addrspace(1) [[GEP]], ptr [[RESULT:%.*]], align 16
+; CHECK-NEXT:    ret void
+;
+  %gep = getelementptr ptr addrspace(1), ptr addrspace(1) %ptr, i64 %index
+  store ptr addrspace(1) %gep, ptr %result
+  ret void
+}


        


More information about the llvm-commits mailing list