[PATCH] D40670: Let Alloca treated as nonnull for any alloca addr space value

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 13:02:55 PST 2017


yaxunl created this revision.
Herald added a subscriber: wdng.

Alloca addr space value depends on target triple. No matter what alloca
addr space value is used, alloca instruction is still an alloca instruction
and should be treated equally.

Currently in ValueTracking.cpp, in function isKnownNonZero, only alloca
instruction with addr space 0 is treated as nonnull, which causes less
performant ISA for target amdgcn---amdgiz since its alloca addr space
is 5.

This patch fixes that.


https://reviews.llvm.org/D40670

Files:
  lib/Analysis/ValueTracking.cpp
  test/Analysis/ValueTracking/alloca-nonnull.ll


Index: test/Analysis/ValueTracking/alloca-nonnull.ll
===================================================================
--- /dev/null
+++ test/Analysis/ValueTracking/alloca-nonnull.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S -instsimplify < %s | FileCheck %s
+
+target datalayout = "A5"
+
+; CHECK: ret i1 true
+define i1 @f()  {
+entry:
+  %a = alloca i32, align 4, addrspace(5)
+  %tobool = icmp ne i32 addrspace(5)* %a, null
+  ret i1 %tobool
+}
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -1860,8 +1860,8 @@
 
   // Check for pointer simplifications.
   if (V->getType()->isPointerTy()) {
-    // Alloca never returns null, malloc might.
-    if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
+    // Alloca never returns null.
+    if (isa<AllocaInst>(V))
       return true;
 
     // A byval, inalloca, or nonnull argument is never null.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40670.124995.patch
Type: text/x-patch
Size: 980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/f3944ad5/attachment.bin>


More information about the llvm-commits mailing list