Skip to content

Commit 48bb7a6

Browse files
committed
cmd/compile: repair bisection behavior for float-to-unsigned conversion
My stab at a bisect-reproducer failed, but I verified that it fixed the problem described in the issue. Updates golang#75834 Change-Id: I9e0dfacd2bbd22cbc557e144920ee3417a48088c Reviewed-on: https://go-review.googlesource.com/c/go/+/710997 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent e8a5353 commit 48bb7a6

File tree

1 file changed

+16
-2
lines changed
  • src/cmd/compile/internal/ssagen

1 file changed

+16
-2
lines changed

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,7 +2865,19 @@ func (s *state) conv(n ir.Node, v *ssa.Value, ft, tt *types.Type) *ssa.Value {
28652865
}
28662866

28672867
if ft.IsFloat() || tt.IsFloat() {
2868-
conv, ok := fpConvOpToSSA[twoTypes{s.concreteEtype(ft), s.concreteEtype(tt)}]
2868+
cft, ctt := s.concreteEtype(ft), s.concreteEtype(tt)
2869+
conv, ok := fpConvOpToSSA[twoTypes{cft, ctt}]
2870+
// there's a change to a conversion-op table, this restores the old behavior if ConvertHash is false.
2871+
// use salted hash to distinguish unsigned convert at a Pos from signed convert at a Pos
2872+
if ctt == types.TUINT32 && ft.IsFloat() && !base.ConvertHash.MatchPosWithInfo(n.Pos(), "U", nil) {
2873+
// revert to old behavior
2874+
conv.op1 = ssa.OpCvt64Fto64
2875+
if cft == types.TFLOAT32 {
2876+
conv.op1 = ssa.OpCvt32Fto64
2877+
}
2878+
conv.op2 = ssa.OpTrunc64to32
2879+
2880+
}
28692881
if s.config.RegSize == 4 && Arch.LinkArch.Family != sys.MIPS && !s.softFloat {
28702882
if conv1, ok1 := fpConvOpToSSA32[twoTypes{s.concreteEtype(ft), s.concreteEtype(tt)}]; ok1 {
28712883
conv = conv1
@@ -5862,6 +5874,7 @@ func (s *state) floatToUint(cvttab *f2uCvtTab, n ir.Node, x *ssa.Value, ft, tt *
58625874
// cutoff:=1<<(intY_Size-1)
58635875
// if x < floatX(cutoff) {
58645876
// result = uintY(x) // bThen
5877+
// // gated by ConvertHash, clamp negative inputs to zero
58655878
// if x < 0 { // unlikely
58665879
// result = 0 // bZero
58675880
// }
@@ -5879,7 +5892,8 @@ func (s *state) floatToUint(cvttab *f2uCvtTab, n ir.Node, x *ssa.Value, ft, tt *
58795892
b.Likely = ssa.BranchLikely
58805893

58815894
var bThen, bZero *ssa.Block
5882-
newConversion := base.ConvertHash.MatchPos(n.Pos(), nil)
5895+
// use salted hash to distinguish unsigned convert at a Pos from signed convert at a Pos
5896+
newConversion := base.ConvertHash.MatchPosWithInfo(n.Pos(), "U", nil)
58835897
if newConversion {
58845898
bZero = s.f.NewBlock(ssa.BlockPlain)
58855899
bThen = s.f.NewBlock(ssa.BlockIf)

0 commit comments

Comments
 (0)