Skip to content

Comments

Copilot Updates#1273

Merged
tgiphil merged 16 commits intomosa:masterfrom
tgiphil:523-copilot
Feb 15, 2026
Merged

Copilot Updates#1273
tgiphil merged 16 commits intomosa:masterfrom
tgiphil:523-copilot

Conversation

@tgiphil
Copy link
Member

@tgiphil tgiphil commented Feb 15, 2026

No description provided.

Added stricter Result matching in StoreLoad* and StoreLoadParam* Match methods to improve transformation accuracy. Updated IfThenElse32Same and IfThenElse64Same to use the correct operand in Move instructions. Minor comment formatting fix in IfThenElse32.
Replaced branch instructions with NOP and added calls to Framework.Transform.UpdatePhiBlock in BranchManagedPointerOnlyOneExit.cs and BranchObjectOnlyOneExit.cs to ensure Phi blocks are updated after branch removal.
Changed target assignment in Transform methods of Branch32OnlyOneExit, Branch64OnlyOneExit, BranchManagedPointerOnlyOneExit, and BranchObjectOnlyOneExit to use context.Block.NextBlocks[0] instead of context.BranchTarget1. This ensures the target is consistently selected from the block's next blocks list. No other logic was modified.
Add a check to ensure divisors do not exceed 32 bits, as GetMagicNumber only supports 32-bit values. Also, explicitly cast 64-bit constants to uint in Transform for type safety.
Changed Transform methods in LoadParamSignExtend32x64Double.cs and LoadParamZeroExtend16x64Double.cs to use IR.Move64 instead of IR.Move32, ensuring correct 64-bit data handling for these operations.
Improved boolean property setters in Node to properly clear flags when set to false, ensuring correct behavior. Updated XML documentation in Context.cs for BranchTargetsCount, and fixed a class name comment in SubCarryOut64.cs.
Correct InsertAfter() XML comment to reflect its behavior, and update the assertion to prevent insertion after block end instructions. Also, reformat copyright header.
@tgiphil tgiphil requested a review from Copilot February 15, 2026 21:29
@tgiphil tgiphil self-assigned this Feb 15, 2026
@tgiphil tgiphil added the Bug label Feb 15, 2026
@tgiphil tgiphil added this to the 2.6 Release milestone Feb 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates several MOSA compiler optimization transforms and core IR helpers to fix incorrect instruction selection, tighten transform matching criteria, and correct option/utility behavior in the framework.

Changes:

  • Fix incorrect IR move widths and operand selection in a few simplification/useless transforms (e.g., 64-bit moves, IfThenElse same-operand simplification).
  • Harden strength-reduction and store/load elimination transforms with additional constant/range checks and operand consistency checks.
  • Fix framework utilities: properly clear InstructionOption flags via boolean setters, and correct Context.InsertAfter() doc/assert behavior.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Useless/LoadParamZeroExtend16x64Double.cs Use Move64 when replacing redundant 64-bit zero-extend.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Useless/LoadParamSignExtend32x64Double.cs Use Move64 when replacing redundant 64-bit sign-extend.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/StrengthReduction/DivUnsignedMagicNumber64.cs Reject divisors > 32-bit and cast safely for GetMagicNumber.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/IfThenElse64Same.cs Fix simplification to move the value operand (not the condition).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/IfThenElse32Same.cs Fix simplification to move the value operand (not the condition).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/BranchObjectOnlyOneExit.cs Remove redundant branch; now also calls UpdatePhiBlock (see review comments).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/BranchManagedPointerOnlyOneExit.cs Remove redundant branch; now also calls UpdatePhiBlock (see review comments).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/Branch64OnlyOneExit.cs Adjust target selection for phi update / redundant-branch removal (see review comments).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/Branch32OnlyOneExit.cs Adjust target selection for phi update / redundant-branch removal (see review comments).
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadR8.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadR4.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadParamR8.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadParamR4.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadParamObject.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadParam64.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadParam32.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoadObject.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoad64.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Memory/StoreLoad32.cs Add check ensuring stored value matches the prior load’s result.
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ConstantFolding/SubCarryOut64.cs Fix summary comment name mismatch.
Source/Mosa.Compiler.Framework/Node.cs Make boolean option setters idempotent (set and clear flags).
Source/Mosa.Compiler.Framework/Context.cs Fix file header, XML comment duplication, and InsertAfter() doc/assert correctness.
Comments suppressed due to low confidence (2)

Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/Branch64OnlyOneExit.cs:26

  • This transform calls UpdatePhiBlock(target) unconditionally after context.SetNop(). When the block still has an unconditional jump to the same target, removing the conditional branch does not remove a predecessor edge, and PhiHelper.UpdatePhi may hit its debug assertion expecting OperandCount != PreviousBlocks.Count. Consider only updating phi nodes if the edge to target was actually removed (check context.Block.NextBlocks after SetNop()).
		var target = context.Block.NextBlocks[0];

		context.SetNop();

		Framework.Transform.UpdatePhiBlock(target);
	}

Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/Simplification/Branch32OnlyOneExit.cs:26

  • This transform calls UpdatePhiBlock(target) unconditionally after context.SetNop(). If the conditional branch is redundant because an unconditional jump still targets the same block, the predecessor set of target does not change and PhiHelper.UpdatePhi can fail its debug assertion expecting a mismatch. Consider guarding the phi update so it only runs when the edge to target was actually removed (e.g., test context.Block.NextBlocks.Contains(target) after SetNop()).
		var target = context.Block.NextBlocks[0];

		context.SetNop();

		Framework.Transform.UpdatePhiBlock(target);
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Correct bit manipulation in Neg64, RemUnsigned, ShiftLeft64, and sign/zero extension methods. Now properly handle full 64-bit values, division by zero checks, and correct bit widths for sign and zero extension. Improves accuracy and consistency in bit-level value propagation.
Refactored UpdateInstruction to more accurately determine constant values for virtual registers. Now uses MinValue when the value is a known constant, BitsSet when all bits are known, and returns early otherwise. This improves constant propagation and bit knowledge handling.
Copy link
Member Author

@tgiphil tgiphil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update bit-tracking logic to use BitsSet for 64-bit zero checks instead of BitsSet32, ensuring correct handling of full 64-bit values. Also, use AreLower32BitsKnown for 32-bit ops in MulUnsigned32. Improves accuracy for multiply, divide, remainder, and shift operations.
Updated RemUnsigned32 to use value2.BitsSet32 instead of value2.BitsSet when narrowing results. This ensures correct handling of 32-bit unsigned remainder operations by applying the appropriate bit width in NarrowMax and NarrowClearBits.
Added handlers for signed division and remainder (DivSigned32, DivSigned64, RemSigned32, RemSigned64) and subtraction operations (Sub32, Sub64, SubCarryIn32, SubCarryIn64) in BitTrackerStage. Registered these in Initialize. Removed carry-out and overflow-out instruction tracking.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tgiphil tgiphil requested a review from Copilot February 15, 2026 22:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Reorganize and comprehensively register all relevant IR instructions in BitTrackerStage.Initialize, ensuring systematic grouping and coverage of arithmetic, logic, shift, move, load, and conversion operations. Add Result2NarrowToBoolean handler for carry/overflow outputs and introduce its implementation. Remove redundant and commented-out code for clarity and maintainability.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tgiphil tgiphil merged commit 4e38b98 into mosa:master Feb 15, 2026
73 checks passed
@tgiphil tgiphil deleted the 523-copilot branch February 16, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant