xref: /llvm-project/llvm/test/Transforms/NewGVN/calloc-load-removal.ll (revision 229640343e400394b315c6798c7c19e8a9bd188c)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2; RUN: opt -S -passes=newgvn < %s | FileCheck %s
3; Check that loads from calloc are recognized as being zero.
4
5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
6
7; Function Attrs: nounwind uwtable
8define i32 @test1() {
9; CHECK-LABEL: define i32 @test1() {
10; CHECK-NEXT:    [[TMP1:%.*]] = tail call noalias ptr @calloc(i64 1, i64 4)
11; CHECK-NEXT:    ret i32 0
12;
13  %1 = tail call noalias ptr @calloc(i64 1, i64 4)
14  ; This load is trivially constant zero
15  %2 = load i32, ptr %1, align 4
16  ret i32 %2
17
18}
19
20declare noalias ptr @calloc(i64, i64) mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) "alloc-family"="malloc"
21