llvm.org GIT mirror llvm / 253ee8c
[InstSimplify] fp_binop X, undef --> NaN The variable operand could be NaN, so it's always safe to propagate NaN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327212 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 2 years ago
3 changed file(s) with 33 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
41554155 if (Constant *C = foldOrCommuteConstant(Instruction::FAdd, Op0, Op1, Q))
41564156 return C;
41574157
4158 if (isa(Op0) || isa(Op1))
4159 return ConstantFP::getNaN(Op0->getType());
4160
41584161 // fadd X, -0 ==> X
41594162 if (match(Op1, m_NegZero()))
41604163 return Op0;
41894192 if (Constant *C = foldOrCommuteConstant(Instruction::FSub, Op0, Op1, Q))
41904193 return C;
41914194
4195 if (isa(Op0) || isa(Op1))
4196 return ConstantFP::getNaN(Op0->getType());
4197
41924198 // fsub X, 0 ==> X
41934199 if (match(Op1, m_Zero()))
41944200 return Op0;
42214227 if (Constant *C = foldOrCommuteConstant(Instruction::FMul, Op0, Op1, Q))
42224228 return C;
42234229
4230 if (isa(Op0) || isa(Op1))
4231 return ConstantFP::getNaN(Op0->getType());
4232
42244233 // fmul X, 1.0 ==> X
42254234 if (match(Op1, m_FPOne()))
42264235 return Op0;
42594268 if (Constant *C = foldOrCommuteConstant(Instruction::FDiv, Op0, Op1, Q))
42604269 return C;
42614270
4262 // undef / X -> undef (the undef could be a snan).
4263 if (match(Op0, m_Undef()))
4264 return Op0;
4265
4266 // X / undef -> undef
4267 if (match(Op1, m_Undef()))
4268 return Op1;
4271 if (isa(Op0) || isa(Op1))
4272 return ConstantFP::getNaN(Op0->getType());
42694273
42704274 // X / 1.0 -> X
42714275 if (match(Op1, m_FPOne()))
43114315 if (Constant *C = foldOrCommuteConstant(Instruction::FRem, Op0, Op1, Q))
43124316 return C;
43134317
4314 // undef % X -> undef (the undef could be a snan).
4315 if (match(Op0, m_Undef()))
4316 return Op0;
4317
4318 // X % undef -> undef
4319 if (match(Op1, m_Undef()))
4320 return Op1;
4318 if (isa(Op0) || isa(Op1))
4319 return ConstantFP::getNaN(Op0->getType());
43214320
43224321 // 0 % X -> 0
43234322 // Requires that NaNs are off (X could be zero) and signed zeroes are
2626 ret double %t2
2727 }
2828
29 define float @fsub_undef(float %val) {
30 ; CHECK-LABEL: @fsub_undef(
31 ; CHECK-NEXT: [[SUB:%.*]] = fsub float [[VAL:%.*]], undef
32 ; CHECK-NEXT: ret float [[SUB]]
33 ;
34 %sub = fsub float %val, undef
35 ret float %sub
36 }
37
38 ; XXX - Why doesn't this fold to undef?
39
40 define float @fsub_fast_undef(float %val) {
41 ; CHECK-LABEL: @fsub_fast_undef(
42 ; CHECK-NEXT: [[SUB:%.*]] = fsub fast float [[VAL:%.*]], undef
43 ; CHECK-NEXT: ret float [[SUB]]
44 ;
45 %sub = fsub fast float %val, undef
46 ret float %sub
47 }
48
22
33 define float @fadd_undef_op0(float %x) {
44 ; CHECK-LABEL: @fadd_undef_op0(
5 ; CHECK-NEXT: [[R:%.*]] = fadd float undef, [[X:%.*]]
6 ; CHECK-NEXT: ret float [[R]]
5 ; CHECK-NEXT: ret float 0x7FF8000000000000
76 ;
87 %r = fadd float undef, %x
98 ret float %r
1110
1211 define float @fadd_undef_op1(float %x) {
1312 ; CHECK-LABEL: @fadd_undef_op1(
14 ; CHECK-NEXT: [[R:%.*]] = fadd float [[X:%.*]], undef
15 ; CHECK-NEXT: ret float [[R]]
13 ; CHECK-NEXT: ret float 0x7FF8000000000000
1614 ;
1715 %r = fadd float %x, undef
1816 ret float %r
2018
2119 define float @fsub_undef_op0(float %x) {
2220 ; CHECK-LABEL: @fsub_undef_op0(
23 ; CHECK-NEXT: [[R:%.*]] = fsub float undef, [[X:%.*]]
24 ; CHECK-NEXT: ret float [[R]]
21 ; CHECK-NEXT: ret float 0x7FF8000000000000
2522 ;
2623 %r = fsub float undef, %x
2724 ret float %r
2926
3027 define float @fsub_undef_op1(float %x) {
3128 ; CHECK-LABEL: @fsub_undef_op1(
32 ; CHECK-NEXT: [[R:%.*]] = fsub float [[X:%.*]], undef
33 ; CHECK-NEXT: ret float [[R]]
29 ; CHECK-NEXT: ret float 0x7FF8000000000000
3430 ;
3531 %r = fsub float %x, undef
3632 ret float %r
3834
3935 define float @fmul_undef_op0(float %x) {
4036 ; CHECK-LABEL: @fmul_undef_op0(
41 ; CHECK-NEXT: [[R:%.*]] = fmul float undef, [[X:%.*]]
42 ; CHECK-NEXT: ret float [[R]]
37 ; CHECK-NEXT: ret float 0x7FF8000000000000
4338 ;
4439 %r = fmul float undef, %x
4540 ret float %r
4742
4843 define float @fmul_undef_op1(float %x) {
4944 ; CHECK-LABEL: @fmul_undef_op1(
50 ; CHECK-NEXT: [[R:%.*]] = fmul float [[X:%.*]], undef
51 ; CHECK-NEXT: ret float [[R]]
45 ; CHECK-NEXT: ret float 0x7FF8000000000000
5246 ;
5347 %r = fmul float %x, undef
5448 ret float %r
5650
5751 define float @fdiv_undef_op0(float %x) {
5852 ; CHECK-LABEL: @fdiv_undef_op0(
59 ; CHECK-NEXT: ret float undef
53 ; CHECK-NEXT: ret float 0x7FF8000000000000
6054 ;
6155 %r = fdiv float undef, %x
6256 ret float %r
6458
6559 define float @fdiv_undef_op1(float %x) {
6660 ; CHECK-LABEL: @fdiv_undef_op1(
67 ; CHECK-NEXT: ret float undef
61 ; CHECK-NEXT: ret float 0x7FF8000000000000
6862 ;
6963 %r = fdiv float %x, undef
7064 ret float %r
7266
7367 define float @frem_undef_op0(float %x) {
7468 ; CHECK-LABEL: @frem_undef_op0(
75 ; CHECK-NEXT: ret float undef
69 ; CHECK-NEXT: ret float 0x7FF8000000000000
7670 ;
7771 %r = frem float undef, %x
7872 ret float %r
8074
8175 define float @frem_undef_op1(float %x) {
8276 ; CHECK-LABEL: @frem_undef_op1(
83 ; CHECK-NEXT: ret float undef
77 ; CHECK-NEXT: ret float 0x7FF8000000000000
8478 ;
8579 %r = frem float %x, undef
8680 ret float %r
9084
9185 define float @fadd_undef_op0_nnan(float %x) {
9286 ; CHECK-LABEL: @fadd_undef_op0_nnan(
93 ; CHECK-NEXT: [[R:%.*]] = fadd nnan float undef, [[X:%.*]]
94 ; CHECK-NEXT: ret float [[R]]
87 ; CHECK-NEXT: ret float 0x7FF8000000000000
9588 ;
9689 %r = fadd nnan float undef, %x
9790 ret float %r
9992
10093 define float @fadd_undef_op1_fast(float %x) {
10194 ; CHECK-LABEL: @fadd_undef_op1_fast(
102 ; CHECK-NEXT: [[R:%.*]] = fadd fast float [[X:%.*]], undef
103 ; CHECK-NEXT: ret float [[R]]
95 ; CHECK-NEXT: ret float 0x7FF8000000000000
10496 ;
10597 %r = fadd fast float %x, undef
10698 ret float %r
108100
109101 define float @fsub_undef_op0_fast(float %x) {
110102 ; CHECK-LABEL: @fsub_undef_op0_fast(
111 ; CHECK-NEXT: [[R:%.*]] = fsub fast float undef, [[X:%.*]]
112 ; CHECK-NEXT: ret float [[R]]
103 ; CHECK-NEXT: ret float 0x7FF8000000000000
113104 ;
114105 %r = fsub fast float undef, %x
115106 ret float %r
117108
118109 define float @fsub_undef_op1_nnan(float %x) {
119110 ; CHECK-LABEL: @fsub_undef_op1_nnan(
120 ; CHECK-NEXT: [[R:%.*]] = fsub nnan float [[X:%.*]], undef
121 ; CHECK-NEXT: ret float [[R]]
111 ; CHECK-NEXT: ret float 0x7FF8000000000000
122112 ;
123113 %r = fsub nnan float %x, undef
124114 ret float %r
126116
127117 define float @fmul_undef_op0_nnan(float %x) {
128118 ; CHECK-LABEL: @fmul_undef_op0_nnan(
129 ; CHECK-NEXT: [[R:%.*]] = fmul nnan float undef, [[X:%.*]]
130 ; CHECK-NEXT: ret float [[R]]
119 ; CHECK-NEXT: ret float 0x7FF8000000000000
131120 ;
132121 %r = fmul nnan float undef, %x
133122 ret float %r
135124
136125 define float @fmul_undef_op1_fast(float %x) {
137126 ; CHECK-LABEL: @fmul_undef_op1_fast(
138 ; CHECK-NEXT: [[R:%.*]] = fmul fast float [[X:%.*]], undef
139 ; CHECK-NEXT: ret float [[R]]
127 ; CHECK-NEXT: ret float 0x7FF8000000000000
140128 ;
141129 %r = fmul fast float %x, undef
142130 ret float %r
144132
145133 define float @fdiv_undef_op0_fast(float %x) {
146134 ; CHECK-LABEL: @fdiv_undef_op0_fast(
147 ; CHECK-NEXT: ret float undef
135 ; CHECK-NEXT: ret float 0x7FF8000000000000
148136 ;
149137 %r = fdiv fast float undef, %x
150138 ret float %r
152140
153141 define float @fdiv_undef_op1_nnan(float %x) {
154142 ; CHECK-LABEL: @fdiv_undef_op1_nnan(
155 ; CHECK-NEXT: ret float undef
143 ; CHECK-NEXT: ret float 0x7FF8000000000000
156144 ;
157145 %r = fdiv nnan float %x, undef
158146 ret float %r
160148
161149 define float @frem_undef_op0_nnan(float %x) {
162150 ; CHECK-LABEL: @frem_undef_op0_nnan(
163 ; CHECK-NEXT: ret float undef
151 ; CHECK-NEXT: ret float 0x7FF8000000000000
164152 ;
165153 %r = frem nnan float undef, %x
166154 ret float %r
168156
169157 define float @frem_undef_op1_fast(float %x) {
170158 ; CHECK-LABEL: @frem_undef_op1_fast(
171 ; CHECK-NEXT: ret float undef
159 ; CHECK-NEXT: ret float 0x7FF8000000000000
172160 ;
173161 %r = frem fast float %x, undef
174162 ret float %r