|
| 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 | + |
| 6 | +target 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" |
| 7 | +target triple = "i386-unknown-linux-gnu" |
| 8 | + |
| 9 | +declare ptr @foo() |
| 10 | +declare i32 @memcmp(ptr inreg nocapture noundef, ptr inreg nocapture noundef, i32 inreg noundef) |
| 11 | +declare i32 @printf(i8*, ...) |
| 12 | +declare double @exp2(double) |
| 13 | +declare i32 @__sprintf_chk(i8*, i32, i32, i8*, ...) |
| 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 nocapture, ptr inreg nocapture, i32 inreg) |
| 19 | +; CHECK-NOT: declare i32 @bcmp(ptr nocapture, ptr nocapture, i32) |
| 20 | + |
| 21 | +define 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 | + |
| 32 | +define void @test_fewer_params_than_num_register_parameters() { |
| 33 | + %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0 |
| 34 | + call i32 (i8*, ...) @printf(i8* %fmt) |
| 35 | + ret void |
| 36 | +} |
| 37 | + |
| 38 | +; CHECK: declare double @ldexp(double, i32 inreg) |
| 39 | +; CHECK-NOT: declare double @ldexp(double, i32) |
| 40 | + |
| 41 | +define double @test_non_int_params(i16 signext %x) { |
| 42 | + %conv = sitofp i16 %x to double |
| 43 | + %ret = call double @exp2(double %conv) |
| 44 | + ret double %ret |
| 45 | +} |
| 46 | + |
| 47 | +; CHECK: declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) |
| 48 | +; CHECK-NOT: declare noundef i32 @sprintf(ptr inreg noalias nocapture noundef writeonly, ptr inreg nocapture noundef readonly, ...) |
| 49 | +define i32 @test_variadic() { |
| 50 | + %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0 |
| 51 | + %fmt = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0 |
| 52 | + %ret = call i32 (i8*, i32, i32, i8*, ...) @__sprintf_chk(i8* %dst, i32 0, i32 -1, i8* %fmt) |
| 53 | + ret i32 %ret |
| 54 | +} |
| 55 | + |
| 56 | +!llvm.module.flags = !{!0} |
| 57 | +!0 = !{i32 1, !"NumRegisterParameters", i32 3} |
0 commit comments