xref: /aosp_15_r20/external/llvm/test/Transforms/InstCombine/strcat-1.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; Test that the strcat libcall simplifier works correctly per the
2*9880d681SAndroid Build Coastguard Worker; bug found in PR3661.
3*9880d681SAndroid Build Coastguard Worker;
4*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S | FileCheck %s
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker@hello = constant [6 x i8] c"hello\00"
9*9880d681SAndroid Build Coastguard Worker@null = constant [1 x i8] zeroinitializer
10*9880d681SAndroid Build Coastguard Worker@null_hello = constant [7 x i8] c"\00hello\00"
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Workerdeclare i8* @strcat(i8*, i8*)
13*9880d681SAndroid Build Coastguard Workerdeclare i32 @puts(i8*)
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerdefine i32 @main() {
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @main(
17*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call i8* @strcat
18*9880d681SAndroid Build Coastguard Worker; CHECK: call i32 @puts
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker  %target = alloca [1024 x i8]
21*9880d681SAndroid Build Coastguard Worker  %arg1 = getelementptr [1024 x i8], [1024 x i8]* %target, i32 0, i32 0
22*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %arg1
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker  ; rslt1 = strcat(target, "hello\00")
25*9880d681SAndroid Build Coastguard Worker  %arg2 = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
26*9880d681SAndroid Build Coastguard Worker  %rslt1 = call i8* @strcat(i8* %arg1, i8* %arg2)
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker  ; rslt2 = strcat(rslt1, "\00")
29*9880d681SAndroid Build Coastguard Worker  %arg3 = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
30*9880d681SAndroid Build Coastguard Worker  %rslt2 = call i8* @strcat(i8* %rslt1, i8* %arg3)
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker  ; rslt3 = strcat(rslt2, "\00hello\00")
33*9880d681SAndroid Build Coastguard Worker  %arg4 = getelementptr [7 x i8], [7 x i8]* @null_hello, i32 0, i32 0
34*9880d681SAndroid Build Coastguard Worker  %rslt3 = call i8* @strcat(i8* %rslt2, i8* %arg4)
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker  call i32 @puts( i8* %rslt3 )
37*9880d681SAndroid Build Coastguard Worker  ret i32 0
38*9880d681SAndroid Build Coastguard Worker}
39