1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 target triple = "nvptx64"
6 declare void @user(ptr)
7 declare ptr @malloc(i64) allockind("alloc,uninitialized") "alloc-family"="malloc" allocsize(0)
8 declare void @free(ptr) allockind("free") "alloc-family"="malloc"
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.
13 define void @malloc_then_free_not_needed() {
14 ; CHECK-LABEL: @malloc_then_free_not_needed(
15 ; CHECK-NEXT: ret void
17 %a = call ptr @malloc(i64 4)
19 call void @free(ptr %a)
23 define 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
30 %a = call ptr @malloc(i64 4)
31 call void @user(ptr %a)
32 call void @free(ptr %a)