[llvm] 6ee11c3 - [NewGVN] Make NewGVN aware of aligned_alloc

Uday Bondhugula via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 10:57:39 PDT 2020


Author: Uday Bondhugula
Date: 2020-04-01T23:26:51+05:30
New Revision: 6ee11c3b0f3605fa45dd7457b650b2d9d1c6ea74

URL: https://github.com/llvm/llvm-project/commit/6ee11c3b0f3605fa45dd7457b650b2d9d1c6ea74
DIFF: https://github.com/llvm/llvm-project/commit/6ee11c3b0f3605fa45dd7457b650b2d9d1c6ea74.diff

LOG: [NewGVN] Make NewGVN aware of aligned_alloc

Make the New GVN pass aware of aligned_alloc.

Depends on D76975.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 17b2c534513d..b93a8bfeaa46 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -1470,7 +1470,8 @@ NewGVN::performSymbolicLoadCoercion(Type *LoadType, Value *LoadPtr,
   // 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,

diff  --git a/llvm/test/Transforms/NewGVN/malloc-load-removal.ll b/llvm/test/Transforms/NewGVN/malloc-load-removal.ll
index 72f4839a5545..c62bac950df2 100644
--- a/llvm/test/Transforms/NewGVN/malloc-load-removal.ll
+++ b/llvm/test/Transforms/NewGVN/malloc-load-removal.ll
@@ -54,3 +54,28 @@ if.end:                                           ; preds = %if.then, %entry
 ; 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
+}


        


More information about the llvm-commits mailing list