Fix two_value boundary condition for unsigned integer overflow.
Correctly handles boundary conditions for unsigned integers in `two_value` to prevent overflow.
A recent change that removed the preference for unsigned types in two_value caused incorrect code generation for boundary conditions involving INT_MAX and INT_MAX+1. This commit reintroduces the preference for unsigned types when precisions match, ensuring that subtractions are performed using unsigned arithmetic and avoiding undefined overflow.
In Details
The match.pd component's two_value condition previously favored unsigned types. After its removal, issues arose with boundary conditions like INT_MAX + 1 due to potential signed overflow. This patch reinstates the preference for unsigned types when precisions are equal, ensuring correct unsigned arithmetic for subtractions and fixing PR127358.
- two_value
- A condition within the GCC match-pass used for comparing two values, often in the context of optimization or pattern matching.
- boundary condition
- A test case or input value that lies at the extreme limits of a range or represents a transition point, often used to expose bugs.
- undefined overflow
- An arithmetic operation where the result exceeds the maximum representable value for the given integer type, leading to unpredictable behavior as per the C/C++ standards.