[llvm] 25002b7 - [InstCombine] Add additional aligned allocation tests for #69474.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 06:49:14 PDT 2023


Author: Florian Hahn
Date: 2023-10-19T14:48:04+01:00
New Revision: 25002b7aeb2f9c64764861d8106a2def57cff9cc

URL: https://github.com/llvm/llvm-project/commit/25002b7aeb2f9c64764861d8106a2def57cff9cc
DIFF: https://github.com/llvm/llvm-project/commit/25002b7aeb2f9c64764861d8106a2def57cff9cc.diff

LOG: [InstCombine] Add additional aligned allocation tests for #69474.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/malloc-free.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/malloc-free.ll b/llvm/test/Transforms/InstCombine/malloc-free.ll
index 29c757f82564ad8..b77f70f239921e8 100644
--- a/llvm/test/Transforms/InstCombine/malloc-free.ll
+++ b/llvm/test/Transforms/InstCombine/malloc-free.ll
@@ -26,8 +26,8 @@ define i32 @dead_aligned_alloc(i32 %size, i32 %alignment, i8 %value) {
   ret i32 0
 }
 
-define i1 @aligned_alloc_only_pointe(i32 %size, i32 %alignment, i8 %value) {
-; CHECK-LABEL: @aligned_alloc_only_pointe(
+define i1 @aligned_alloc_pointer_only_used_by_cmp(i32 %size, i32 %alignment, i8 %value) {
+; CHECK-LABEL: @aligned_alloc_pointer_only_used_by_cmp(
 ; CHECK-NEXT:    ret i1 true
 ;
   %aligned_allocation = tail call ptr @aligned_alloc(i32 %alignment, i32 %size)
@@ -35,9 +35,49 @@ define i1 @aligned_alloc_only_pointe(i32 %size, i32 %alignment, i8 %value) {
   ret i1 %cmp
 }
 
+define i1 @aligned_alloc_pointer_only_used_by_cmp_alignment_and_value_known_ok(i32 %size, i32 %alignment, i8 %value) {
+; CHECK-LABEL: @aligned_alloc_pointer_only_used_by_cmp_alignment_and_value_known_ok(
+; CHECK-NEXT:    ret i1 true
+;
+  %aligned_allocation = tail call ptr @aligned_alloc(i32 8, i32 32)
+  %cmp = icmp ne ptr %aligned_allocation, null
+  ret i1 %cmp
+}
+
+define i1 @aligned_alloc_pointer_only_used_by_cmp_alignment_no_power_of_2(i32 %size, i32 %alignment, i8 %value) {
+; CHECK-LABEL: @aligned_alloc_pointer_only_used_by_cmp_alignment_no_power_of_2(
+; CHECK-NEXT:    ret i1 true
+;
+  %aligned_allocation = tail call ptr @aligned_alloc(i32 3, i32 32)
+  %cmp = icmp ne ptr %aligned_allocation, null
+  ret i1 %cmp
+}
+
+define i1 @aligned_alloc_pointer_only_used_by_cmp_size_not_multiple_of_alignment(i32 %size, i32 %alignment, i8 %value) {
+; CHECK-LABEL: @aligned_alloc_pointer_only_used_by_cmp_size_not_multiple_of_alignment(
+; CHECK-NEXT:    ret i1 true
+;
+  %aligned_allocation = tail call ptr @aligned_alloc(i32 8, i32 31)
+  %cmp = icmp ne ptr %aligned_allocation, null
+  ret i1 %cmp
+}
+
+; This test uses a aligned allocation function 
diff erent to @aligned_alloc,
+; and should be treated as having @aligned_alloc's constraints on alignment
+; and size operands.
+define i1 @other_aligned_allocation_function(i32 %size, i32 %alignment, i8 %value) {
+; CHECK-LABEL: @other_aligned_allocation_function(
+; CHECK-NEXT:    ret i1 true
+;
+  %aligned_allocation = tail call ptr @other_aligned_alloc(i32 %alignment, i32 %size)
+  %cmp = icmp ne ptr %aligned_allocation, null
+  ret i1 %cmp
+}
+
 declare noalias ptr @calloc(i32, i32) nounwind allockind("alloc,zeroed") allocsize(0,1) "alloc-family"="malloc"
 declare noalias ptr @malloc(i32) allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc"
 declare noalias ptr @aligned_alloc(i32, i32) allockind("alloc,uninitialized,aligned") allocsize(1) "alloc-family"="malloc"
+declare noalias ptr @other_aligned_alloc(i32, i32) allockind("alloc,uninitialized,aligned") allocsize(1) "alloc-family"="malloc"
 declare void @free(ptr) allockind("free") "alloc-family"="malloc"
 
 define i1 @foo() {


        


More information about the llvm-commits mailing list