From 4f15b54780af7159732794f9d67c9a8a455bbf61 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 28 Nov 2018 12:41:23 -0800 Subject: [PATCH] cmd/compile: ensure S390X moves don't overflow int32 Break ADDconst into ADD + MOVDconst, so that if the constant is too big it won't overflow ADDconst's constant field. For normal sizes, other rules will recombine into an ADDconst. Fixes S390X breakage from CL 33909. Change-Id: Id804ee052365527efb580f797688b0ce83c47915 Reviewed-on: https://go-review.googlesource.com/c/151597 Run-TryBot: Keith Randall Reviewed-by: Michael Munday --- src/cmd/compile/internal/ssa/gen/S390X.rules | 2 +- src/cmd/compile/internal/ssa/rewriteS390X.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules index de2c09c2d1d..0aeea535616 100644 --- a/src/cmd/compile/internal/ssa/gen/S390X.rules +++ b/src/cmd/compile/internal/ssa/gen/S390X.rules @@ -350,7 +350,7 @@ // Move more than 1024 bytes using a loop. (Move [s] dst src mem) && s > 1024 -> - (LoweredMove [s%256] dst src (ADDconst src [(s/256)*256]) mem) + (LoweredMove [s%256] dst src (ADD src (MOVDconst [(s/256)*256])) mem) // Lowering Zero instructions (Zero [0] _ mem) -> mem diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index dce7a525290..1695b087809 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -4799,7 +4799,7 @@ func rewriteValueS390X_OpMove_10(v *Value) bool { } // match: (Move [s] dst src mem) // cond: s > 1024 - // result: (LoweredMove [s%256] dst src (ADDconst src [(s/256)*256]) mem) + // result: (LoweredMove [s%256] dst src (ADD src (MOVDconst [(s/256)*256])) mem) for { s := v.AuxInt _ = v.Args[2] @@ -4813,9 +4813,11 @@ func rewriteValueS390X_OpMove_10(v *Value) bool { v.AuxInt = s % 256 v.AddArg(dst) v.AddArg(src) - v0 := b.NewValue0(v.Pos, OpS390XADDconst, src.Type) - v0.AuxInt = (s / 256) * 256 + v0 := b.NewValue0(v.Pos, OpS390XADD, src.Type) v0.AddArg(src) + v1 := b.NewValue0(v.Pos, OpS390XMOVDconst, typ.UInt64) + v1.AuxInt = (s / 256) * 256 + v0.AddArg(v1) v.AddArg(v0) v.AddArg(mem) return true