You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, lowered cse combines the two CMPQconst values (v11, v9), but not the two SBBQcarrymask instructions that use them (v12, v18), because they have different types.
As a result, the CMP occurs only once, but the first SBBQ clobbers the flags, making the second SBBQ wrong. We need to find all instructions that clobber flags, mark them as such, and teach the register allocator both about clobbering and about how to save/restore flags.
For completeness, just before codegen, the function reads:
Yes, we have to add flags clobbering to (almost) everything. And flags spill/restore.
It might be worth changing the type of the SBBQs to match so they get CSEd. I'll leave it for now though, so we have an obvious test case for this issue.
This code is currently miscompiled:
With tip, it correctly prints 97. With SSA, it prints 0. I found this because it caused the
fmt
package tests to fail.Diagnosis:
Just before lowering, the SSA looks good:
The lowered form is fine:
However, lowered cse combines the two
CMPQconst
values (v11
,v9
), but not the twoSBBQcarrymask
instructions that use them (v12
,v18
), because they have different types.As a result, the CMP occurs only once, but the first SBBQ clobbers the flags, making the second SBBQ wrong. We need to find all instructions that clobber flags, mark them as such, and teach the register allocator both about clobbering and about how to save/restore flags.
For completeness, just before codegen, the function reads:
And the generated assembly is:
The value v22 (instruction 15) is wrong.
/cc @randall77
The text was updated successfully, but these errors were encountered: