xref: /llvm-project/llvm/test/Transforms/InstCombine/malloc_free_delete_nvptx.ll (revision 4ab40eca080965c65802710e39adbb78c4ce7bde)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4target triple = "nvptx64"
5
6declare void @user(ptr)
7declare ptr @malloc(i64) allockind("alloc,uninitialized") "alloc-family"="malloc" allocsize(0)
8declare void @free(ptr) allockind("free") "alloc-family"="malloc"
9
10; Ensure the nvptx backend states malloc & free are a thing so we can recognize
11; so we will optimize them properly. In the test below the malloc-free chain is
12; useless and we can remove it *if* we know about malloc & free.
13define void @malloc_then_free_not_needed() {
14; CHECK-LABEL: @malloc_then_free_not_needed(
15; CHECK-NEXT:    ret void
16;
17  %a = call ptr @malloc(i64 4)
18  store i8 0, ptr %a
19  call void @free(ptr %a)
20  ret void
21}
22
23define void @malloc_then_free_needed() {
24; CHECK-LABEL: @malloc_then_free_needed(
25; CHECK-NEXT:    [[A:%.*]] = call dereferenceable_or_null(4) ptr @malloc(i64 4)
26; CHECK-NEXT:    call void @user(ptr [[A]])
27; CHECK-NEXT:    call void @free(ptr [[A]])
28; CHECK-NEXT:    ret void
29;
30  %a = call ptr @malloc(i64 4)
31  call void @user(ptr %a)
32  call void @free(ptr %a)
33  ret void
34}
35