xref: /llvm-project/llvm/test/Transforms/InstCombine/simplify-libcalls-inreg.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; RUN: opt -passes=instcombine -S %s | FileCheck %s
2
3; The intent of this test is to check that the declarations produces for
4; libcalls retains the inreg parameter attribute.
5
6target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
7target triple = "i386-unknown-linux-gnu"
8
9declare ptr @foo()
10declare i32 @memcmp(ptr inreg captures(none) noundef, ptr inreg captures(none) noundef, i32 inreg noundef)
11declare i32 @printf(ptr, ...)
12declare double @exp2(double)
13declare i32 @__sprintf_chk(ptr, i32, i32, ptr, ...)
14@a = common global [60 x i8] zeroinitializer, align 1
15@b = common global [60 x i8] zeroinitializer, align 1
16@h = constant [2 x i8] c"h\00"
17
18; CHECK:     declare i32 @bcmp(ptr inreg captures(none), ptr inreg captures(none), i32 inreg)
19; CHECK-NOT: declare i32 @bcmp(ptr captures(none), ptr captures(none), i32)
20
21define i32 @baz(ptr inreg noundef %s2, i32 inreg noundef %n){
22  %call = call ptr @foo()
23  %call1 = call i32 @memcmp(ptr inreg noundef %call, ptr inreg noundef %s2, i32 inreg noundef %n)
24  %cmp = icmp eq i32 %call1, 0
25  %conv = zext i1 %cmp to i32
26  ret i32 %conv
27}
28
29; CHECK:     declare noundef i32 @putchar(i32 inreg noundef)
30; CHECK-NOT: declare noundef i32 @putchar(i32 noundef)
31
32define void @test_fewer_params_than_num_register_parameters() {
33  call i32 (ptr, ...) @printf(ptr @h)
34  ret void
35}
36
37; CHECK:     declare double @ldexp(double, i32 inreg)
38; CHECK-NOT: declare double @ldexp(double, i32)
39
40define double @test_non_int_params(i16 signext %x) {
41  %conv = sitofp i16 %x to double
42  %ret = call double @exp2(double %conv)
43  ret double %ret
44}
45
46; CHECK:     declare noundef i32 @sprintf(ptr noalias noundef writeonly captures(none), ptr noundef readonly captures(none), ...)
47; CHECK-NOT: declare noundef i32 @sprintf(ptr inreg noalias noundef writeonly captures(none), ptr inreg noundef readonly captures(none), ...)
48define i32 @test_variadic() {
49  %ret = call i32 (ptr, i32, i32, ptr, ...) @__sprintf_chk(ptr @a, i32 0, i32 -1, ptr @b)
50  ret i32 %ret
51}
52
53!llvm.module.flags = !{!0}
54!0 = !{i32 1, !"NumRegisterParameters", i32 3}
55