]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: convert uint32 to int32 in ARM constant folding rules
authorCherry Zhang <cherryyz@google.com>
Thu, 21 Jun 2018 14:59:19 +0000 (10:59 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 22 Jun 2018 16:25:32 +0000 (16:25 +0000)
MOVWconst's AuxInt is Int32. SSA check complains if the AuxInt
does not fit in int32. Convert uint32 to int32 to make it happy.

The generated code is unchanged. MOVW only cares low 32 bits.

Passes "toolstash -cmp" std cmd for ARM.

Fixes #25993.

Change-Id: I2b6532c9c285ea6d89652505fb7c553f85a98864
Reviewed-on: https://go-review.googlesource.com/120335
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/ARM.rules
src/cmd/compile/internal/ssa/rewriteARM.go
test/fixedbugs/issue25993.go [new file with mode: 0644]

index 4714becd7326381de592f7b998a2e272d599cb51..65b11c998068dfb2f161d487ecfb4769bb1c865f 100644 (file)
 (RSBconst [c] (SUBconst [d] x)) -> (RSBconst [int64(int32(c+d))] x)
 (RSCconst [c] (ADDconst [d] x) flags) -> (RSCconst [int64(int32(c-d))] x flags)
 (RSCconst [c] (SUBconst [d] x) flags) -> (RSCconst [int64(int32(c+d))] x flags)
-(SLLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(uint32(d)<<uint64(c))])
-(SRLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(uint32(d)>>uint64(c))])
+(SLLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)<<uint64(c)))])
+(SRLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)>>uint64(c)))])
 (SRAconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d)>>uint64(c))])
 (MUL (MOVWconst [c]) (MOVWconst [d])) -> (MOVWconst [int64(int32(c*d))])
 (MULA (MOVWconst [c]) (MOVWconst [d]) a) -> (ADDconst [int64(int32(c*d))] a)
 (MULS (MOVWconst [c]) (MOVWconst [d]) a) -> (SUBconst [int64(int32(c*d))] a)
-(Select0 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(uint32(c)/uint32(d))])
-(Select1 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(uint32(c)%uint32(d))])
+(Select0 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)/uint32(d)))])
+(Select1 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)%uint32(d)))])
 (ANDconst [c] (MOVWconst [d])) -> (MOVWconst [c&d])
 (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c&d] x)
 (ORconst [c] (MOVWconst [d])) -> (MOVWconst [c|d])
 (MOVWreg (MOVWconst [c])) -> (MOVWconst [c])
 // BFX: Width = c >> 8, LSB = c & 0xff, result = d << (32 - Width - LSB) >> (32 - Width)
 (BFX [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8)))])
-(BFXU [c] (MOVWconst [d])) -> (MOVWconst [int64(uint32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8)))])
+(BFXU [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8))))])
 
 // absorb shifts into ops
 (ADD x (SLLconst [c] y)) -> (ADDshiftLL x y [c])
index 2622913eae8dca2e8bed1746c8a5aeeb587c506f..1eb32285cd1f81d291d3b39a04a18aaebdad4b6c 100644 (file)
@@ -4044,7 +4044,7 @@ func rewriteValueARM_OpARMBFX_0(v *Value) bool {
 func rewriteValueARM_OpARMBFXU_0(v *Value) bool {
        // match: (BFXU [c] (MOVWconst [d]))
        // cond:
-       // result: (MOVWconst [int64(uint32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8)))])
+       // result: (MOVWconst [int64(int32(uint32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8))))])
        for {
                c := v.AuxInt
                v_0 := v.Args[0]
@@ -4053,7 +4053,7 @@ func rewriteValueARM_OpARMBFXU_0(v *Value) bool {
                }
                d := v_0.AuxInt
                v.reset(OpARMMOVWconst)
-               v.AuxInt = int64(uint32(d) << (32 - uint32(c&0xff) - uint32(c>>8)) >> (32 - uint32(c>>8)))
+               v.AuxInt = int64(int32(uint32(d) << (32 - uint32(c&0xff) - uint32(c>>8)) >> (32 - uint32(c>>8))))
                return true
        }
        return false
@@ -14103,7 +14103,7 @@ func rewriteValueARM_OpARMSLL_0(v *Value) bool {
 func rewriteValueARM_OpARMSLLconst_0(v *Value) bool {
        // match: (SLLconst [c] (MOVWconst [d]))
        // cond:
-       // result: (MOVWconst [int64(uint32(d)<<uint64(c))])
+       // result: (MOVWconst [int64(int32(uint32(d)<<uint64(c)))])
        for {
                c := v.AuxInt
                v_0 := v.Args[0]
@@ -14112,7 +14112,7 @@ func rewriteValueARM_OpARMSLLconst_0(v *Value) bool {
                }
                d := v_0.AuxInt
                v.reset(OpARMMOVWconst)
-               v.AuxInt = int64(uint32(d) << uint64(c))
+               v.AuxInt = int64(int32(uint32(d) << uint64(c)))
                return true
        }
        return false
@@ -14274,7 +14274,7 @@ func rewriteValueARM_OpARMSRL_0(v *Value) bool {
 func rewriteValueARM_OpARMSRLconst_0(v *Value) bool {
        // match: (SRLconst [c] (MOVWconst [d]))
        // cond:
-       // result: (MOVWconst [int64(uint32(d)>>uint64(c))])
+       // result: (MOVWconst [int64(int32(uint32(d)>>uint64(c)))])
        for {
                c := v.AuxInt
                v_0 := v.Args[0]
@@ -14283,7 +14283,7 @@ func rewriteValueARM_OpARMSRLconst_0(v *Value) bool {
                }
                d := v_0.AuxInt
                v.reset(OpARMMOVWconst)
-               v.AuxInt = int64(uint32(d) >> uint64(c))
+               v.AuxInt = int64(int32(uint32(d) >> uint64(c)))
                return true
        }
        // match: (SRLconst (SLLconst x [c]) [d])
@@ -21295,7 +21295,7 @@ func rewriteValueARM_OpSelect0_0(v *Value) bool {
        }
        // match: (Select0 (CALLudiv (MOVWconst [c]) (MOVWconst [d])))
        // cond:
-       // result: (MOVWconst [int64(uint32(c)/uint32(d))])
+       // result: (MOVWconst [int64(int32(uint32(c)/uint32(d)))])
        for {
                v_0 := v.Args[0]
                if v_0.Op != OpARMCALLudiv {
@@ -21313,7 +21313,7 @@ func rewriteValueARM_OpSelect0_0(v *Value) bool {
                }
                d := v_0_1.AuxInt
                v.reset(OpARMMOVWconst)
-               v.AuxInt = int64(uint32(c) / uint32(d))
+               v.AuxInt = int64(int32(uint32(c) / uint32(d)))
                return true
        }
        return false
@@ -21364,7 +21364,7 @@ func rewriteValueARM_OpSelect1_0(v *Value) bool {
        }
        // match: (Select1 (CALLudiv (MOVWconst [c]) (MOVWconst [d])))
        // cond:
-       // result: (MOVWconst [int64(uint32(c)%uint32(d))])
+       // result: (MOVWconst [int64(int32(uint32(c)%uint32(d)))])
        for {
                v_0 := v.Args[0]
                if v_0.Op != OpARMCALLudiv {
@@ -21382,7 +21382,7 @@ func rewriteValueARM_OpSelect1_0(v *Value) bool {
                }
                d := v_0_1.AuxInt
                v.reset(OpARMMOVWconst)
-               v.AuxInt = int64(uint32(c) % uint32(d))
+               v.AuxInt = int64(int32(uint32(c) % uint32(d)))
                return true
        }
        return false
diff --git a/test/fixedbugs/issue25993.go b/test/fixedbugs/issue25993.go
new file mode 100644 (file)
index 0000000..3253cd8
--- /dev/null
@@ -0,0 +1,21 @@
+// compile -d=ssa/check/on
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 25993: SSA check fails on ARM.
+
+package p
+
+func f() {
+       var x int
+       var B0 bool
+       B0 = !B0 || B0
+       if B0 && B0 {
+               x = -1
+       }
+       var AI []int
+       var AB []bool
+       _ = AI[x] > 0 && AB[x]
+}