GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-ssa-loop-im

tree-ssa-loop-im: Reject trapping store motion with non-call EH

Disallows moving stores out of loops when non-call exceptions are enabled to prevent incorrect behavior.

The loop invariant motion (LIM) pass in GCC incorrectly handled exception information when moving stores out of loops. Previously, it treated bare memory references as loads, and a safe load didn’t prove a store to the same address couldn’t trap. This change ensures that trapping stores are rejected when exception handling is enabled and non-call exceptions can be thrown, preventing potential runtime errors. A new test case verifies this behavior.

In Details

The tree-ssa-loop-im.cc pass handles loop-invariant memory motion. The can_sm_ref_p function, which determines if a store motion reference is safe, previously did not adequately consider exception-throwing behavior. This commit corrects can_sm_ref_p to reject trapping stores when tree_could_throw_p indicates non-call exceptions are possible, ensuring EH correctness for loop transformations.

For Context
LIM
Loop Invariant Motion, a compiler optimization that moves loop-independent computations outside a loop to reduce redundant work.
EH
Exception Handling, the mechanism used by a program to handle runtime errors or exceptional conditions.
tree-ssa
Static Single Assignment form, an intermediate representation used by GCC that makes many optimizations easier to implement by ensuring each variable is assigned only once.
trap
An event where a program instruction causes an immediate, synchronous interruption due to an error, such as division by zero or accessing invalid memory.
Filed Under: optimizationexception handling