[dev.ssa] cmd/compile: truncate auxint when constructing Prog
The upper bits of 8/16/32 bit constants are undefined. We need to
truncate in order to prevent x86.oclass misidentifying the size of the
constant.
Fixes #14389
Change-Id: I3e5ff79cd904376572a93f489ba7e152a5cb6e60
Reviewed-on: https://go-review.googlesource.com/19740
Reviewed-by: Keith Randall <khr@golang.org>
diff --git a/src/cmd/compile/internal/ssa/value.go b/src/cmd/compile/internal/ssa/value.go
index c2ea6ee..cc8c9fe 100644
--- a/src/cmd/compile/internal/ssa/value.go
+++ b/src/cmd/compile/internal/ssa/value.go
@@ -77,6 +77,25 @@
}
return int32(v.AuxInt)
}
+
+// AuxInt2Int64 is used to sign extend the lower bits of AuxInt according to
+// the size of AuxInt specified in the opcode table.
+func (v *Value) AuxInt2Int64() int64 {
+ switch opcodeTable[v.Op].auxType {
+ case auxInt64:
+ return v.AuxInt
+ case auxInt32:
+ return int64(int32(v.AuxInt))
+ case auxInt16:
+ return int64(int16(v.AuxInt))
+ case auxInt8:
+ return int64(int8(v.AuxInt))
+ default:
+ v.Fatalf("op %s doesn't have an aux int field", v.Op)
+ return -1
+ }
+}
+
func (v *Value) AuxFloat() float64 {
if opcodeTable[v.Op].auxType != auxFloat {
v.Fatalf("op %s doesn't have a float aux field", v.Op)