[PATCH] D76976: [NewGVN] Make NewGVN aware of aligned_alloc

Uday Bondhugula via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 10:59:29 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ee11c3b0f36: [NewGVN] Make NewGVN aware of aligned_alloc (authored by bondhugula).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76976/new/

https://reviews.llvm.org/D76976

Files:
  llvm/lib/Transforms/Scalar/NewGVN.cpp
  llvm/test/Transforms/NewGVN/malloc-load-removal.ll


Index: llvm/test/Transforms/NewGVN/malloc-load-removal.ll
===================================================================
--- llvm/test/Transforms/NewGVN/malloc-load-removal.ll
+++ llvm/test/Transforms/NewGVN/malloc-load-removal.ll
@@ -54,3 +54,28 @@
 ; CHECK_NO_LIBCALLS: load
 ; CHECK_NO_LIBCALLS: icmp
 }
+
+declare i8* @aligned_alloc(i64, i64) nounwind
+
+define noalias i8* @test3() nounwind uwtable ssp {
+entry:
+  %call = tail call i8* @aligned_alloc(i64 256, i64 32) nounwind
+  %0 = load i8, i8* %call, align 32
+  %tobool = icmp eq i8 %0, 0
+  br i1 %tobool, label %if.end, label %if.then
+
+if.then:                                          ; preds = %entry
+  store i8 0, i8* %call, align 1
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  ret i8* %call
+
+; CHECK-LABEL: @test3(
+; CHECK-NOT: load
+; CHECK-NOT: icmp
+
+; CHECK_NO_LIBCALLS-LABEL: @test3(
+; CHECK_NO_LIBCALLS: load
+; CHECK_NO_LIBCALLS: icmp
+}
Index: llvm/lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -1470,7 +1470,8 @@
   // undef value.  This can happen when loading for a fresh allocation with no
   // intervening stores, for example.  Note that this is only true in the case
   // that the result of the allocation is pointer equal to the load ptr.
-  if (isa<AllocaInst>(DepInst) || isMallocLikeFn(DepInst, TLI)) {
+  if (isa<AllocaInst>(DepInst) || isMallocLikeFn(DepInst, TLI) ||
+      isAlignedAllocLikeFn(DepInst, TLI)) {
     return createConstantExpression(UndefValue::get(LoadType));
   }
   // If this load occurs either right after a lifetime begin,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76976.254257.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200401/ae719c81/attachment.bin>


More information about the llvm-commits mailing list