@@ -2561,22 +2561,25 @@ func (e *edgeState) processDest(loc Location, vid ID, splice **Value, pos src.XP
25612561 e .s .f .Fatalf ("can't find source for %s->%s: %s\n " , e .p , e .b , v .LongString ())
25622562 }
25632563 if dstReg {
2564- // Handle incompatible registers.
2564+ // We want to rematerialize v into a register that is incompatible with v's op's register mask.
2565+ // Instead of setting the wrong register for the rematerialized v, we should find the right register
2566+ // for it and emit an additional copy to move to the desired register.
25652567 // For #70451.
2566- if e .s .regspec (v ).outputs [0 ].regs & regMask (1 << register (loc .(* Register ).num )) == 0 && c != nil {
2568+ if e .s .regspec (v ).outputs [0 ].regs & regMask (1 << register (loc .(* Register ).num )) == 0 {
25672569 _ , srcReg := src .(* Register )
2568- if ! srcReg {
2570+ if srcReg {
2571+ // It exists in a valid register already, so just copy it to the desired register
2572+ // If src is a Register, c must have already been set.
2573+ x = e .p .NewValue1 (pos , OpCopy , c .Type , c )
2574+ } else {
25692575 // We need a tmp register
25702576 x = v .copyInto (e .p )
25712577 r := e .findRegFor (x .Type )
25722578 e .erase (r )
2573- // Rematerialize to a tmp register
2579+ // Rematerialize to the tmp register
25742580 e .set (r , vid , x , false , pos )
25752581 // Copy from tmp to the desired register
25762582 x = e .p .NewValue1 (pos , OpCopy , x .Type , x )
2577- } else {
2578- // It exist in a valid register already, so just copy it to the desired register
2579- x = e .p .NewValue1 (pos , OpCopy , c .Type , c )
25802583 }
25812584 } else {
25822585 x = v .copyInto (e .p )
0 commit comments