35 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 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 recognize11; so we will optimize them properly. In the test below the malloc-free chain is12; 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 void16;17 %a = call ptr @malloc(i64 4)18 store i8 0, ptr %a19 call void @free(ptr %a)20 ret void21}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 void29;30 %a = call ptr @malloc(i64 4)31 call void @user(ptr %a)32 call void @free(ptr %a)33 ret void34}35