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

Krzysztof Drewniak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 13:49:20 PST 2023


krzysz00 created this revision.
Herald added a subscriber: arphaman.
Herald added a project: All.
krzysz00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143435

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


Index: llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll
===================================================================
--- /dev/null
+++ 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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143435.495266.patch
Type: text/x-patch
Size: 1919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230206/25932ff1/attachment.bin>


More information about the llvm-commits mailing list