GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
gcc

Fix dest = cond ? x : -1 when STORE_FLAG_VALUE is -1

Bug fix in GCC's if-conversion optimization corrects handling of conditional assignments to -1 when STORE_FLAG_VALUE is -1.

A bug in GCC’s ifcvt.cc pass, affecting conditional assignments of the form dest = cond ? x : -1, has been fixed. The issue occurred when STORE_FLAG_VALUE was set to -1, leading to incorrect tense handling in the generated code. This commit corrects the logic for platforms like m68k and gcn, ensuring accurate conditional assignments in such scenarios.

In Details

The noce_try_store_flag_logical function in ifcvt.cc previously handled the STORE_FLAG_VALUE == 1 case for if-conversion but failed to correctly account for the inverted tense when STORE_FLAG_VALUE == -1. This commit fixes that by removing an unnecessary subtract-one step specific to the STORE_FLAG_VALUE == 1 case, which was incorrectly applied to the -1 case.

For Context
if-conversion
An optimization technique that transforms conditional control flow (if-statements) into conditional move instructions. This can improve performance by reducing branch mispredictions.
STORE_FLAG_VALUE
A target-specific macro that defines the value used to represent a false condition after a comparison instruction. Typically, this is 0 or 1, but can be -1 on some architectures.
SCC insn
Set Conditional instruction. This is a machine instruction that sets a destination register based on the outcome of a previous comparison or condition-code-setting instruction.
rtl-optimization
Optimization passes operating on GCC's intermediate representation called Register Transfer Language (RTL). These passes perform machine-independent optimizations before target-specific code generation.
Filed Under: optimizationbugfixm68k