GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
or1k

OpenRISC fixes conditional branch instruction placement

GCC for OpenRISC now correctly places `cbranchsi4` instructions by explicitly declaring its clobbering of the status register flag, preventing miscompilations…

This commit resolves an issue in the OpenRISC GCC backend where the cbranchsi4 instruction was improperly placed during optimization, leading to incorrect code generation. The cbranchsi4 instruction pattern now explicitly indicates that it clobbers the status register flag (sr_f), allowing the compiler’s middle-end to avoid injecting other instructions between the comparison and the jump. This fix prevents test failures related to arithmetic overflow checks.

In Details

The cbranchsi4 instruction pattern on OpenRISC is expanded into a sequence involving setting the status register flag (sr_f) based on a comparison, followed by a conditional jump using that flag. Between the combine and late_combine1 passes, the GCC middle-end could inadvertently insert other instructions that would clobber sr_f if not explicitly aware of the cbranchsi4 expansion. By adding a clobber clause for sr_f to the cbranchsi4 pattern in or1k.md, the instruction scheduler is informed of this side effect, ensuring correct instruction placement and preventing incorrect…

For Context

Compilers optimize your code by rearranging instructions to make them run faster. On a processor like OpenRISC, a conditional if statement (which the compiler represents as a cbranchsi4 instruction) is actually split into two parts: first, a comparison sets a special 'status flag' in a register, and then a jump instruction checks that flag. Sometimes, the compiler's optimizers might accidentally put other instructions in between these two parts, which would change the status flag before the jump can check it. This change tells the compiler that the cbranchsi4 instruction 'uses up' or 'clobbers' this status flag, so the optimizer knows not to place any other instructions there that would interfere with it. This ensures that conditional jumps work correctly and prevents bugs in the compiled program.

Filed Under: or1kbugfixoptimizationcode_generation