GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
s390

s390: Fix s390_canonicalize_comparison

Fixes s390 canonicalization of comparisons involving non-register operands for CC_TO_INT.

This commit corrects the s390_canonicalize_comparison function to properly handle comparisons where the operand for UNSPEC_CC_TO_INT might not be a register. Previously, the function assumed this operand was always a register, which could lead to issues when dealing with instructions like TDC_INSN followed by CC_TO_INT. The update ensures that the function verifies this operand is indeed a register, preventing incorrect code generation. Additionally, the change standardizes the check for register types from GET_CODE (x) == REG to the more robust REG_P (x).

In Details

The s390_canonicalize_comparison function handles the canonicalization of comparison instructions. This patch addresses a failure case where the UNSPEC_CC_TO_INT instruction's operand (which should typically be a register after UNSPEC_TDC_INSN) is not a register. This can occur with the instruction sequence TDC_INSN -> CC_TO_INT. The fix adds a check to ensure that the operand for UNSPEC_CC_TO_INT is a register (REG_P(x)) rather than relying on GET_CODE (x) == REG. This prevents potential ICEs or incorrect code generation when such non-register operands arise.

For Context
s390
IBM mainframe architecture. GCC supports generating code for this architecture.
canonicalize
To transform an expression or instruction into a standard or canonical form. This process simplifies analysis and optimization by ensuring that equivalent operations have a consistent representation.
UNSPEC_TDC_INSN
An internal GCC representation for a specific s390 instruction or operation, likely related to Test under Mask or similar bit manipulation instructions.
UNSPEC_CC_TO_INT
An internal GCC representation for converting a condition code (CC) status into an integer value on the s390 architecture.
REG_P
A predicate macro or function in GCC used to check if a given GCC tree node represents a register.
Filed Under: s390comparisoncompiler buginstruction selection