Only remove REG_EQUAL/EQUIV notes on successful optimization
Fixes a bug in the extended dead code elimination pass where REG_EQUAL/EQUIV notes were removed even when the optimization failed.
This commit fixes a bug in the extended dead code elimination (ext-dce) pass. Previously, REG_EQUAL and REG_EQUIV notes were unconditionally removed after attempting an optimization, even if the optimization failed during validation. This could lead to incorrect code generation in subsequent passes because the REG_EQUAL hint was lost on an unchanged instruction. Now, the note removal is guarded by a flag that ensures notes are only removed when the transformation is successfully committed.
In Details
This commit addresses a correctness issue in ext-dce.cc within the ext_dce_try_optimize_extension function. The REG_EQUAL/REG_EQUIV notes were being removed regardless of whether the validate_change call succeeded. This commit now guards the note removal with the 'ok' flag, ensuring they are only removed upon a successful optimization. This prevents miscompilation in subsequent passes due to loss of REG_EQUAL information.
For Context
This commit fixes a bug in GCC's optimization process related to how the compiler tracks information about the values of registers. The compiler uses notes to remember when two registers have the same value. A bug was found where these notes were being removed prematurely, even if the optimization that created them didn't actually happen. This could cause the compiler to make incorrect assumptions later on, leading to incorrect machine code. This fix ensures that these notes are only removed when the optimization is successful.