xref: /aosp_15_r20/external/llvm/test/Transforms/GVN/malloc-load-removal.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -basicaa -gvn -disable-simplify-libcalls < %s | FileCheck %s -check-prefix=CHECK_NO_LIBCALLS
3*9880d681SAndroid Build Coastguard Worker; PR13694
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Workertarget 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*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-macosx10.8.0"
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workerdeclare i8* @malloc(i64) nounwind
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Workerdefine noalias i8* @test1() nounwind uwtable ssp {
11*9880d681SAndroid Build Coastguard Workerentry:
12*9880d681SAndroid Build Coastguard Worker  %call = tail call i8* @malloc(i64 100) nounwind
13*9880d681SAndroid Build Coastguard Worker  %0 = load i8, i8* %call, align 1
14*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i8 %0, 0
15*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %if.end, label %if.then
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
18*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %call, align 1
19*9880d681SAndroid Build Coastguard Worker  br label %if.end
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Workerif.end:                                           ; preds = %if.then, %entry
22*9880d681SAndroid Build Coastguard Worker  ret i8* %call
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1(
25*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
26*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: icmp
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS-LABEL: @test1(
29*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS: load
30*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS: icmp
31*9880d681SAndroid Build Coastguard Worker}
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Workerdeclare i8* @_Znwm(i64) nounwind
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerdefine noalias i8* @test2() nounwind uwtable ssp {
36*9880d681SAndroid Build Coastguard Workerentry:
37*9880d681SAndroid Build Coastguard Worker  %call = tail call i8* @_Znwm(i64 100) nounwind
38*9880d681SAndroid Build Coastguard Worker  %0 = load i8, i8* %call, align 1
39*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i8 %0, 0
40*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %if.end, label %if.then
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Workerif.then:                                          ; preds = %entry
43*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %call, align 1
44*9880d681SAndroid Build Coastguard Worker  br label %if.end
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Workerif.end:                                           ; preds = %if.then, %entry
47*9880d681SAndroid Build Coastguard Worker  ret i8* %call
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2(
50*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
51*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: icmp
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS-LABEL: @test2(
54*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS: load
55*9880d681SAndroid Build Coastguard Worker; CHECK_NO_LIBCALLS: icmp
56*9880d681SAndroid Build Coastguard Worker}
57