ranger: Fix up wi_fold_in_parts for small precision types [PR104334]
authorJakub Jelinek <jakub@redhat.com>
Thu, 3 Feb 2022 08:45:16 +0000 (09:45 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 3 Feb 2022 08:45:16 +0000 (09:45 +0100)
commitde67f943b858099b40f73632a51e66147ec79c9b
tree9b52aaa46e288416f582859387b7d3ea46e3df2c
parent54d21dd5b5c5c5539505b3e037cdecb3b0ab3918
ranger: Fix up wi_fold_in_parts for small precision types [PR104334]

The wide-int.h templates expect that when an int/long etc. operand is used
it will be sign-extended based on the types precision.
wi_fold_in_parts passes 3 such non-zero constants to wi::lt_p, wi::gt_p
and wi::eq_p - 1, 3 and 4, which means it was doing weird things if either
some of 1, 3 or 4 weren't representable in type, or if type was unsigned 3 bit
type 4 should be written as -4.
The following patch promotes the subtraction operands to widest_int and
uses that as the type for ?h_range variables and compares them as such.
We don't need the overflow handling because there is never an overflow.

2022-02-02  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/104334
* range-op.cc (range_operator::wi_fold_in_parts): Change lh_range
and rh_range type to widest_int and subtract in widest_int.  Remove
ov_rh, ov_lh and sign vars, always perform comparisons as signed
and use >, < and == operators for it.

* g++.dg/opt/pr104334.C: New test.
gcc/range-op.cc
gcc/testsuite/g++.dg/opt/pr104334.C [new file with mode: 0644]