1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target triple = "nvptx64"
6 declare void @user(i8*)
7 declare i8* @malloc(i64)
8 declare void @free(i8*)
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 i8* @malloc(i64 4)
19 call void @free(i8* %a)
23 define void @malloc_then_free_needed() {
24 ; CHECK-LABEL: @malloc_then_free_needed(
25 ; CHECK-NEXT: [[A:%.*]] = call dereferenceable_or_null(4) i8* @malloc(i64 4)
26 ; CHECK-NEXT: call void @user(i8* [[A]])
27 ; CHECK-NEXT: call void @free(i8* [[A]])
28 ; CHECK-NEXT: ret void
30 %a = call i8* @malloc(i64 4)
31 call void @user(i8* %a)
32 call void @free(i8* %a)