[llvm] a68c968 - [ValueTracking] Correctly check addrspace of alloca
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 04:11:35 PDT 2023
Author: Nikita Popov
Date: 2023-06-23T13:11:28+02:00
New Revision: a68c9687556696522e0d3ee62857714250d58a93
URL: https://github.com/llvm/llvm-project/commit/a68c9687556696522e0d3ee62857714250d58a93
DIFF: https://github.com/llvm/llvm-project/commit/a68c9687556696522e0d3ee62857714250d58a93.diff
LOG: [ValueTracking] Correctly check addrspace of alloca
The DataLayout alloca address space is the address space that should
be used when creating new allocas. However, not all allocas are
required to be in this address space. The isKnownNonZero() check
should work on the actual address space of the alloca, not the
default alloca address space.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 66e810ce634d3..278bdd0ab5710 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2588,7 +2588,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
if (PointerType *PtrTy = dyn_cast<PointerType>(V->getType())) {
// Alloca never returns null, malloc might.
- if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
+ if (isa<AllocaInst>(V) && PtrTy->getAddressSpace() == 0)
return true;
// A byval, inalloca may not be null in a non-default addres space. A
diff --git a/llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll b/llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll
index 079b728d38245..f5634c080bd29 100644
--- a/llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll
+++ b/llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll
@@ -12,7 +12,7 @@ define weak amdgpu_kernel void @__omp_offloading_802_ea0109_main_l8(ptr %a) {
; CHECK-LABEL: @__omp_offloading_802_ea0109_main_l8(
; CHECK-NEXT: .master:
; CHECK-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 1
-; CHECK-NEXT: call void @use(ptr [[TMP0]], ptr [[TMP0]])
+; CHECK-NEXT: call void @use(ptr nonnull [[TMP0]], ptr nonnull [[TMP0]])
; CHECK-NEXT: ret void
;
.master:
@@ -28,7 +28,7 @@ define void @spam(ptr %arg1) {
; CHECK-LABEL: @spam(
; CHECK-NEXT: bb:
; CHECK-NEXT: [[ALLOCA1:%.*]] = alloca [0 x [30 x %struct.widget]], align 16
-; CHECK-NEXT: call void @zot(ptr [[ALLOCA1]])
+; CHECK-NEXT: call void @zot(ptr nonnull [[ALLOCA1]])
; CHECK-NEXT: ret void
;
bb:
@@ -37,4 +37,29 @@ bb:
ret void
}
+define i1 @alloca_addrspace_0_nonnull() {
+; CHECK-LABEL: @alloca_addrspace_0_nonnull(
+; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i8, align 1
+; CHECK-NEXT: call void @use(ptr nonnull [[ALLOCA]], ptr null)
+; CHECK-NEXT: ret i1 true
+;
+ %alloca = alloca i8
+ call void @use(ptr %alloca)
+ %cmp = icmp ne ptr %alloca, null
+ ret i1 %cmp
+}
+
+define i1 @alloca_addrspace_5_nonnull() {
+; CHECK-LABEL: @alloca_addrspace_5_nonnull(
+; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i8, align 1, addrspace(5)
+; CHECK-NEXT: call void @use(ptr addrspace(5) [[ALLOCA]])
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(5) [[ALLOCA]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %alloca = alloca i8, addrspace(5)
+ call void @use(ptr addrspace(5) %alloca)
+ %cmp = icmp ne ptr addrspace(5) %alloca, null
+ ret i1 %cmp
+}
+
declare hidden void @zot(ptr)
More information about the llvm-commits
mailing list