xref: /llvm-project/llvm/test/Transforms/FunctionSpecialization/solver-constants.ll (revision 88e9b373c0d7184b08c755024cce0778d18f0306)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
2; RUN: opt -passes="ipsccp<func-spec>" -funcspec-min-function-size=1       \
3; RUN:                                 -funcspec-for-literal-constant=true \
4; RUN:                                 -funcspec-min-codesize-savings=50   \
5; RUN:                                 -funcspec-min-latency-savings=0     \
6; RUN:                                 -S < %s | FileCheck %s
7
8; Verify that we are able to estimate the codesize savings arising from a branch
9; based on a binary operator, where one operand is already found constant by
10; IPSCCP.
11define i32 @main(i1 %flag) {
12  %notspec = call i32 @test(i1 %flag, i1 false)
13  %spec = call i32 @test(i1 false, i1 false)
14  %sum = add i32 %notspec, %spec
15  ret i32 %sum
16}
17
18define internal i32 @test(i1 %argflag, i1 %constflag) {
19entry:
20  %cond = or i1 %argflag, %constflag
21  br i1 %cond, label %if.then, label %if.end
22
23if.then:
24  call void @do_something()
25  call void @do_something()
26  call void @do_something()
27  call void @do_something()
28  br label %if.end
29
30if.end:
31  %res = phi i32 [ 0, %entry ], [ 1, %if.then]
32  ret i32 %res
33}
34
35declare void @do_something()
36; CHECK-LABEL: define range(i32 0, 2) i32 @main(
37; CHECK-SAME: i1 [[FLAG:%.*]]) {
38; CHECK-NEXT:    [[NOTSPEC:%.*]] = call i32 @test(i1 [[FLAG]], i1 false)
39; CHECK-NEXT:    [[SPEC:%.*]] = call i32 @test.specialized.1(i1 false, i1 false)
40; CHECK-NEXT:    [[SUM:%.*]] = add nuw nsw i32 [[NOTSPEC]], 0
41; CHECK-NEXT:    ret i32 [[SUM]]
42;
43;
44; CHECK-LABEL: define internal range(i32 0, 2) i32 @test(
45; CHECK-SAME: i1 [[ARGFLAG:%.*]], i1 [[CONSTFLAG:%.*]]) {
46; CHECK-NEXT:  [[ENTRY:.*]]:
47; CHECK-NEXT:    [[COND:%.*]] = or i1 [[ARGFLAG]], false
48; CHECK-NEXT:    br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_END:.*]]
49; CHECK:       [[IF_THEN]]:
50; CHECK-NEXT:    call void @do_something()
51; CHECK-NEXT:    call void @do_something()
52; CHECK-NEXT:    call void @do_something()
53; CHECK-NEXT:    call void @do_something()
54; CHECK-NEXT:    br label %[[IF_END]]
55; CHECK:       [[IF_END]]:
56; CHECK-NEXT:    [[RES:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ 1, %[[IF_THEN]] ]
57; CHECK-NEXT:    ret i32 [[RES]]
58;
59;
60; CHECK-LABEL: define internal i32 @test.specialized.1(
61; CHECK-SAME: i1 [[ARGFLAG:%.*]], i1 [[CONSTFLAG:%.*]]) {
62; CHECK-NEXT:  [[ENTRY:.*:]]
63; CHECK-NEXT:    br label %[[IF_END:.*]]
64; CHECK:       [[IF_END]]:
65; CHECK-NEXT:    ret i32 poison
66;
67