gcov: Optimize condition coverage code generation
Gcov avoids generating no-op bitwise-or operations for condition coverage, reducing redundant code.
This commit optimizes gcov’s condition coverage instrumentation by preventing the generation of redundant bitwise-or operations with a zero constant operand. These operations are effectively no-ops and can lead to unnecessary code, especially when using atomic operations for profiling updates. The change ensures these redundant operations are omitted during the profile code generation phase, resulting in cleaner and potentially more efficient assembly output.
In Details
Optimizes instrument_decisions in tree-profile.cc by folding bitwise-OR operations with a zero constant operand using gimple_build() instead of gimple_build_assign(). This change prevents the emission of no-op instructions, which is crucial because these operations, if materialized as relaxed atomic operations, cannot be optimized away later. The optimization is performed during profile code generation, not as a subsequent GIMPLE optimization pass.
- gcov
- A code coverage tool provided with GCC that analyzes program execution to determine which parts of the code are exercised by tests.
- bit-wise OR
- A binary operation that compares corresponding bits of two numbers. If either bit is 1, the result bit is 1; otherwise, it is 0.
- constant operand
- A fixed value, such as a number or string, used in an operation, rather than a variable whose value might change.
- GIMPLE
- GCC's InternalМнемоник Expression. A three-address intermediate representation used by the compiler optimization passes.
- atomic operations
- Operations that are performed as a single, indivisible unit, typically used in multithreaded programming to ensure data integrity when multiple threads access shared resources.