aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/SCCP/sitofp.ll
blob: b635263a5726c2ee2b5f129773fe7681f116fdc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=ipsccp -S < %s | FileCheck %s

define float @sitofp_and(i8 %x) {
; CHECK-LABEL: @sitofp_and(
; CHECK-NEXT:    [[PX:%.*]] = and i8 [[X:%.*]], 127
; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[PX]] to float
; CHECK-NEXT:    ret float [[R]]
;
  %px = and i8 %x, 127
  %r = sitofp i8 %px to float
  ret float %r
}

define half @sitofp_const(i8 %x) {
; CHECK-LABEL: @sitofp_const(
; CHECK-NEXT:    ret half 0xH5140
;
  %r = sitofp i8 42 to half
  ret half %r
}

define double @sitofp_zext(i7 %x) {
; CHECK-LABEL: @sitofp_zext(
; CHECK-NEXT:    [[PX:%.*]] = zext i7 [[X:%.*]] to i8
; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[PX]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %px = zext i7 %x to i8
  %r = sitofp i8 %px to double
  ret double %r
}

; negative test

define double @sitofp_not_nonneg(i7 %x) {
; CHECK-LABEL: @sitofp_not_nonneg(
; CHECK-NEXT:    [[PX:%.*]] = sext i7 [[X:%.*]] to i8
; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[PX]] to double
; CHECK-NEXT:    ret double [[R]]
;
  %px = sext i7 %x to i8
  %r = sitofp i8 %px to double
  ret double %r
}

; x is known non-negative in t block

define float @dominating_condition(i32 %x) {
; CHECK-LABEL: @dominating_condition(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[X:%.*]], 0
; CHECK-NEXT:    br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK:       t:
; CHECK-NEXT:    [[A:%.*]] = sitofp i32 [[X]] to float
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       f:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       exit:
; CHECK-NEXT:    [[COND:%.*]] = phi float [ [[A]], [[T]] ], [ 4.200000e+01, [[F]] ]
; CHECK-NEXT:    ret float [[COND]]
;
entry:
  %cmp = icmp sge i32 %x, 0
  br i1 %cmp, label %t, label %f

t:
  %a = sitofp i32 %x to float
  br label %exit

f:
  br label %exit

exit:
  %cond = phi float [ %a, %t ], [ 42.0, %f ]
  ret float %cond
}

; x is known non-negative in f block

define float @dominating_condition_alt(i32 %x) {
; CHECK-LABEL: @dominating_condition_alt(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], 2000000000
; CHECK-NEXT:    br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK:       t:
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       f:
; CHECK-NEXT:    [[A:%.*]] = sitofp i32 [[X]] to float
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       exit:
; CHECK-NEXT:    [[COND:%.*]] = phi float [ -4.200000e+01, [[T]] ], [ [[A]], [[F]] ]
; CHECK-NEXT:    ret float [[COND]]
;
entry:
  %cmp = icmp ugt i32 %x, 2000000000
  br i1 %cmp, label %t, label %f

t:
  br label %exit

f:
  %a = sitofp i32 %x to float
  br label %exit

exit:
  %cond = phi float [ -42.0, %t ], [ %a, %f ]
  ret float %cond
}