|
44 | 44 | (Trunc64to8 (Const64 [c])) -> (Const8 [int64(int8(c))])
|
45 | 45 | (Trunc64to16 (Const64 [c])) -> (Const16 [int64(int16(c))])
|
46 | 46 | (Trunc64to32 (Const64 [c])) -> (Const32 [int64(int32(c))])
|
47 |
| -(Cvt64Fto32F (Const64F [c])) -> (Const32F [f2i(float64(i2f32(c)))]) |
| 47 | +(Cvt64Fto32F (Const64F [c])) -> (Const32F [auxFrom32F(float32(auxTo64F(c)))]) |
48 | 48 | (Cvt32Fto64F (Const32F [c])) -> (Const64F [c]) // c is already a 64 bit float
|
49 |
| -(Cvt32to32F (Const32 [c])) -> (Const32F [f2i(float64(float32(int32(c))))]) |
50 |
| -(Cvt32to64F (Const32 [c])) -> (Const64F [f2i(float64(int32(c)))]) |
51 |
| -(Cvt64to32F (Const64 [c])) -> (Const32F [f2i(float64(float32(c)))]) |
52 |
| -(Cvt64to64F (Const64 [c])) -> (Const64F [f2i(float64(c))]) |
53 |
| -(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(i2f(c)))]) |
54 |
| -(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(i2f(c))]) |
55 |
| -(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(i2f(c)))]) |
56 |
| -(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(i2f(c))]) |
| 49 | +(Cvt32to32F (Const32 [c])) -> (Const32F [auxFrom32F(float32(int32(c)))]) |
| 50 | +(Cvt32to64F (Const32 [c])) -> (Const64F [auxFrom64F(float64(int32(c)))]) |
| 51 | +(Cvt64to32F (Const64 [c])) -> (Const32F [auxFrom32F(float32(c))]) |
| 52 | +(Cvt64to64F (Const64 [c])) -> (Const64F [auxFrom64F(float64(c))]) |
| 53 | +(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(auxTo32F(c)))]) |
| 54 | +(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(auxTo32F(c))]) |
| 55 | +(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(auxTo64F(c)))]) |
| 56 | +(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(auxTo64F(c))]) |
57 | 57 | (Round32F x:(Const32F)) -> x
|
58 | 58 | (Round64F x:(Const64F)) -> x
|
59 | 59 |
|
|
95 | 95 | (Neg16 (Const16 [c])) -> (Const16 [int64(-int16(c))])
|
96 | 96 | (Neg32 (Const32 [c])) -> (Const32 [int64(-int32(c))])
|
97 | 97 | (Neg64 (Const64 [c])) -> (Const64 [-c])
|
98 |
| -(Neg32F (Const32F [c])) && i2f(c) != 0 -> (Const32F [f2i(-i2f(c))]) |
99 |
| -(Neg64F (Const64F [c])) && i2f(c) != 0 -> (Const64F [f2i(-i2f(c))]) |
| 98 | +(Neg32F (Const32F [c])) && auxTo32F(c) != 0 -> (Const32F [auxFrom32F(-auxTo32F(c))]) |
| 99 | +(Neg64F (Const64F [c])) && auxTo64F(c) != 0 -> (Const64F [auxFrom64F(-auxTo64F(c))]) |
100 | 100 |
|
101 | 101 | (Add8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c+d))])
|
102 | 102 | (Add16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c+d))])
|
103 | 103 | (Add32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c+d))])
|
104 | 104 | (Add64 (Const64 [c]) (Const64 [d])) -> (Const64 [c+d])
|
105 |
| -(Add32F (Const32F [c]) (Const32F [d])) -> |
106 |
| - (Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) // ensure we combine the operands with 32 bit precision |
107 |
| -(Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) + i2f(d))]) |
| 105 | +(Add32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) + auxTo32F(d))]) |
| 106 | +(Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) + auxTo64F(d))]) |
108 | 107 | (AddPtr <t> x (Const64 [c])) -> (OffPtr <t> x [c])
|
109 | 108 | (AddPtr <t> x (Const32 [c])) -> (OffPtr <t> x [c])
|
110 | 109 |
|
111 | 110 | (Sub8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c-d))])
|
112 | 111 | (Sub16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c-d))])
|
113 | 112 | (Sub32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c-d))])
|
114 | 113 | (Sub64 (Const64 [c]) (Const64 [d])) -> (Const64 [c-d])
|
115 |
| -(Sub32F (Const32F [c]) (Const32F [d])) -> |
116 |
| - (Const32F [f2i(float64(i2f32(c) - i2f32(d)))]) |
117 |
| -(Sub64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) - i2f(d))]) |
| 114 | +(Sub32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) - auxTo32F(d))]) |
| 115 | +(Sub64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) - auxTo64F(d))]) |
118 | 116 |
|
119 | 117 | (Mul8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c*d))])
|
120 | 118 | (Mul16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c*d))])
|
121 | 119 | (Mul32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c*d))])
|
122 | 120 | (Mul64 (Const64 [c]) (Const64 [d])) -> (Const64 [c*d])
|
123 |
| -(Mul32F (Const32F [c]) (Const32F [d])) -> |
124 |
| - (Const32F [f2i(float64(i2f32(c) * i2f32(d)))]) |
125 |
| -(Mul64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) * i2f(d))]) |
| 121 | +(Mul32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) * auxTo32F(d))]) |
| 122 | +(Mul64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) * auxTo64F(d))]) |
126 | 123 |
|
127 | 124 | (And8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c&d))])
|
128 | 125 | (And16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c&d))])
|
|
147 | 144 | (Div16u (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(int16(uint16(c)/uint16(d)))])
|
148 | 145 | (Div32u (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(int32(uint32(c)/uint32(d)))])
|
149 | 146 | (Div64u (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [int64(uint64(c)/uint64(d))])
|
150 |
| -(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))]) |
151 |
| -(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))]) |
| 147 | +(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) / auxTo32F(d))]) |
| 148 | +(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) / auxTo64F(d))]) |
152 | 149 |
|
153 | 150 | (Not (ConstBool [c])) -> (ConstBool [1-c])
|
154 | 151 |
|
|
444 | 441 | (Leq8U (Const8 [c]) (Const8 [d])) -> (ConstBool [b2i(uint8(c) <= uint8(d))])
|
445 | 442 |
|
446 | 443 | // constant floating point comparisons
|
447 |
| -(Eq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) == i2f(d))]) |
448 |
| -(Neq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) != i2f(d))]) |
449 |
| -(Greater(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) > i2f(d))]) |
450 |
| -(Geq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) >= i2f(d))]) |
451 |
| -(Less(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) < i2f(d))]) |
452 |
| -(Leq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) <= i2f(d))]) |
| 444 | +(Eq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) == auxTo32F(d))]) |
| 445 | +(Eq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) == auxTo64F(d))]) |
| 446 | +(Neq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) != auxTo32F(d))]) |
| 447 | +(Neq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) != auxTo64F(d))]) |
| 448 | +(Greater32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) > auxTo32F(d))]) |
| 449 | +(Greater64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) > auxTo64F(d))]) |
| 450 | +(Geq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) >= auxTo32F(d))]) |
| 451 | +(Geq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) >= auxTo64F(d))]) |
| 452 | +(Less32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) < auxTo32F(d))]) |
| 453 | +(Less64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) < auxTo64F(d))]) |
| 454 | +(Leq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) <= auxTo32F(d))]) |
| 455 | +(Leq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) <= auxTo64F(d))]) |
453 | 456 |
|
454 | 457 | // simplifications
|
455 | 458 | (Or(64|32|16|8) x x) -> x
|
|
572 | 575 |
|
573 | 576 | // Pass constants through math.Float{32,64}bits and math.Float{32,64}frombits
|
574 | 577 | (Load <t1> p1 (Store {t2} p2 (Const64 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitFloat(t1) -> (Const64F [x])
|
575 |
| -(Load <t1> p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [f2i(extend32Fto64F(math.Float32frombits(uint32(x))))]) |
| 578 | +(Load <t1> p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [auxFrom32F(math.Float32frombits(uint32(x)))]) |
576 | 579 | (Load <t1> p1 (Store {t2} p2 (Const64F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitInt(t1) -> (Const64 [x])
|
577 |
| -(Load <t1> p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(truncate64Fto32F(i2f(x)))))]) |
| 580 | +(Load <t1> p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(auxTo32F(x))))]) |
578 | 581 |
|
579 | 582 | // Float Loads up to Zeros so they can be constant folded.
|
580 | 583 | (Load <t1> op:(OffPtr [o1] p1)
|
|
1329 | 1332 | (Add(32|64)F x (Const(32|64)F [0])) -> x
|
1330 | 1333 | (Sub(32|64)F x (Const(32|64)F [0])) -> x
|
1331 | 1334 |
|
1332 |
| -(Mul(32|64)F x (Const(32|64)F [f2i(1)])) -> x |
1333 |
| -(Mul32F x (Const32F [f2i(-1)])) -> (Neg32F x) |
1334 |
| -(Mul64F x (Const64F [f2i(-1)])) -> (Neg64F x) |
1335 |
| -(Mul32F x (Const32F [f2i(2)])) -> (Add32F x x) |
1336 |
| -(Mul64F x (Const64F [f2i(2)])) -> (Add64F x x) |
| 1335 | +(Mul(32|64)F x (Const(32|64)F [auxFrom64F(1)])) -> x |
| 1336 | +(Mul32F x (Const32F [auxFrom32F(-1)])) -> (Neg32F x) |
| 1337 | +(Mul64F x (Const64F [auxFrom64F(-1)])) -> (Neg64F x) |
| 1338 | +(Mul32F x (Const32F [auxFrom32F(2)])) -> (Add32F x x) |
| 1339 | +(Mul64F x (Const64F [auxFrom64F(2)])) -> (Add64F x x) |
1337 | 1340 |
|
1338 |
| -(Div32F x (Const32F <t> [c])) && reciprocalExact32(float32(i2f(c))) -> (Mul32F x (Const32F <t> [f2i(1/i2f(c))])) |
1339 |
| -(Div64F x (Const64F <t> [c])) && reciprocalExact64(i2f(c)) -> (Mul64F x (Const64F <t> [f2i(1/i2f(c))])) |
| 1341 | +(Div32F x (Const32F <t> [c])) && reciprocalExact32(auxTo32F(c)) -> (Mul32F x (Const32F <t> [auxFrom32F(1/auxTo32F(c))])) |
| 1342 | +(Div64F x (Const64F <t> [c])) && reciprocalExact64(auxTo64F(c)) -> (Mul64F x (Const64F <t> [auxFrom64F(1/auxTo64F(c))])) |
1340 | 1343 |
|
1341 |
| -(Sqrt (Const64F [c])) -> (Const64F [f2i(math.Sqrt(i2f(c)))]) |
| 1344 | +(Sqrt (Const64F [c])) -> (Const64F [auxFrom64F(math.Sqrt(auxTo64F(c)))]) |
1342 | 1345 |
|
1343 | 1346 | // recognize runtime.newobject and don't Zero/Nilcheck it
|
1344 | 1347 | (Zero (Load (OffPtr [c] (SP)) mem) mem)
|
|
0 commit comments