xref: /llvm-project/llvm/test/Transforms/SCCP/sitofp.ll (revision 6243395d7f1da6a2ea813f5d86ba71f91e1070bf)
1bf1fe249SSanjay Patel; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2bf1fe249SSanjay Patel; RUN: opt -passes=ipsccp -S < %s | FileCheck %s
3bf1fe249SSanjay Patel
4bf1fe249SSanjay Pateldefine float @sitofp_and(i8 %x) {
5bf1fe249SSanjay Patel; CHECK-LABEL: @sitofp_and(
6bf1fe249SSanjay Patel; CHECK-NEXT:    [[PX:%.*]] = and i8 [[X:%.*]], 127
7*6243395dSNoah Goldstein; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[PX]] to float
8bf1fe249SSanjay Patel; CHECK-NEXT:    ret float [[R]]
9bf1fe249SSanjay Patel;
10bf1fe249SSanjay Patel  %px = and i8 %x, 127
11bf1fe249SSanjay Patel  %r = sitofp i8 %px to float
12bf1fe249SSanjay Patel  ret float %r
13bf1fe249SSanjay Patel}
14bf1fe249SSanjay Patel
15bf1fe249SSanjay Pateldefine half @sitofp_const(i8 %x) {
16bf1fe249SSanjay Patel; CHECK-LABEL: @sitofp_const(
17bf1fe249SSanjay Patel; CHECK-NEXT:    ret half 0xH5140
18bf1fe249SSanjay Patel;
19bf1fe249SSanjay Patel  %r = sitofp i8 42 to half
20bf1fe249SSanjay Patel  ret half %r
21bf1fe249SSanjay Patel}
22bf1fe249SSanjay Patel
23bf1fe249SSanjay Pateldefine double @sitofp_zext(i7 %x) {
24bf1fe249SSanjay Patel; CHECK-LABEL: @sitofp_zext(
25bf1fe249SSanjay Patel; CHECK-NEXT:    [[PX:%.*]] = zext i7 [[X:%.*]] to i8
26*6243395dSNoah Goldstein; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[PX]] to double
27bf1fe249SSanjay Patel; CHECK-NEXT:    ret double [[R]]
28bf1fe249SSanjay Patel;
29bf1fe249SSanjay Patel  %px = zext i7 %x to i8
30bf1fe249SSanjay Patel  %r = sitofp i8 %px to double
31bf1fe249SSanjay Patel  ret double %r
32bf1fe249SSanjay Patel}
33bf1fe249SSanjay Patel
34bf1fe249SSanjay Patel; negative test
35bf1fe249SSanjay Patel
36bf1fe249SSanjay Pateldefine double @sitofp_not_nonneg(i7 %x) {
37bf1fe249SSanjay Patel; CHECK-LABEL: @sitofp_not_nonneg(
38bf1fe249SSanjay Patel; CHECK-NEXT:    [[PX:%.*]] = sext i7 [[X:%.*]] to i8
39bf1fe249SSanjay Patel; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[PX]] to double
40bf1fe249SSanjay Patel; CHECK-NEXT:    ret double [[R]]
41bf1fe249SSanjay Patel;
42bf1fe249SSanjay Patel  %px = sext i7 %x to i8
43bf1fe249SSanjay Patel  %r = sitofp i8 %px to double
44bf1fe249SSanjay Patel  ret double %r
45bf1fe249SSanjay Patel}
46bf1fe249SSanjay Patel
47bf1fe249SSanjay Patel; x is known non-negative in t block
48bf1fe249SSanjay Patel
49bf1fe249SSanjay Pateldefine float @dominating_condition(i32 %x) {
50bf1fe249SSanjay Patel; CHECK-LABEL: @dominating_condition(
51bf1fe249SSanjay Patel; CHECK-NEXT:  entry:
52bf1fe249SSanjay Patel; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[X:%.*]], 0
53bf1fe249SSanjay Patel; CHECK-NEXT:    br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
54bf1fe249SSanjay Patel; CHECK:       t:
55*6243395dSNoah Goldstein; CHECK-NEXT:    [[A:%.*]] = uitofp nneg i32 [[X]] to float
56bf1fe249SSanjay Patel; CHECK-NEXT:    br label [[EXIT:%.*]]
57bf1fe249SSanjay Patel; CHECK:       f:
58bf1fe249SSanjay Patel; CHECK-NEXT:    br label [[EXIT]]
59bf1fe249SSanjay Patel; CHECK:       exit:
60bf1fe249SSanjay Patel; CHECK-NEXT:    [[COND:%.*]] = phi float [ [[A]], [[T]] ], [ 4.200000e+01, [[F]] ]
61bf1fe249SSanjay Patel; CHECK-NEXT:    ret float [[COND]]
62bf1fe249SSanjay Patel;
63bf1fe249SSanjay Patelentry:
64bf1fe249SSanjay Patel  %cmp = icmp sge i32 %x, 0
65bf1fe249SSanjay Patel  br i1 %cmp, label %t, label %f
66bf1fe249SSanjay Patel
67bf1fe249SSanjay Patelt:
68bf1fe249SSanjay Patel  %a = sitofp i32 %x to float
69bf1fe249SSanjay Patel  br label %exit
70bf1fe249SSanjay Patel
71bf1fe249SSanjay Patelf:
72bf1fe249SSanjay Patel  br label %exit
73bf1fe249SSanjay Patel
74bf1fe249SSanjay Patelexit:
75bf1fe249SSanjay Patel  %cond = phi float [ %a, %t ], [ 42.0, %f ]
76bf1fe249SSanjay Patel  ret float %cond
77bf1fe249SSanjay Patel}
78bf1fe249SSanjay Patel
79bf1fe249SSanjay Patel; x is known non-negative in f block
80bf1fe249SSanjay Patel
81bf1fe249SSanjay Pateldefine float @dominating_condition_alt(i32 %x) {
82bf1fe249SSanjay Patel; CHECK-LABEL: @dominating_condition_alt(
83bf1fe249SSanjay Patel; CHECK-NEXT:  entry:
84bf1fe249SSanjay Patel; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], 2000000000
85bf1fe249SSanjay Patel; CHECK-NEXT:    br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
86bf1fe249SSanjay Patel; CHECK:       t:
87bf1fe249SSanjay Patel; CHECK-NEXT:    br label [[EXIT:%.*]]
88bf1fe249SSanjay Patel; CHECK:       f:
89*6243395dSNoah Goldstein; CHECK-NEXT:    [[A:%.*]] = uitofp nneg i32 [[X]] to float
90bf1fe249SSanjay Patel; CHECK-NEXT:    br label [[EXIT]]
91bf1fe249SSanjay Patel; CHECK:       exit:
92bf1fe249SSanjay Patel; CHECK-NEXT:    [[COND:%.*]] = phi float [ -4.200000e+01, [[T]] ], [ [[A]], [[F]] ]
93bf1fe249SSanjay Patel; CHECK-NEXT:    ret float [[COND]]
94bf1fe249SSanjay Patel;
95bf1fe249SSanjay Patelentry:
96bf1fe249SSanjay Patel  %cmp = icmp ugt i32 %x, 2000000000
97bf1fe249SSanjay Patel  br i1 %cmp, label %t, label %f
98bf1fe249SSanjay Patel
99bf1fe249SSanjay Patelt:
100bf1fe249SSanjay Patel  br label %exit
101bf1fe249SSanjay Patel
102bf1fe249SSanjay Patelf:
103bf1fe249SSanjay Patel  %a = sitofp i32 %x to float
104bf1fe249SSanjay Patel  br label %exit
105bf1fe249SSanjay Patel
106bf1fe249SSanjay Patelexit:
107bf1fe249SSanjay Patel  %cond = phi float [ -42.0, %t ], [ %a, %f ]
108bf1fe249SSanjay Patel  ret float %cond
109bf1fe249SSanjay Patel}
110