match.pd: Demote IFN_{ADD,SUB,MUL}_OVERFLOW operands [PR99591]
authorJakub Jelinek <jakub@redhat.com>
Thu, 2 Sep 2021 09:25:07 +0000 (11:25 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 2 Sep 2021 09:25:07 +0000 (11:25 +0200)
commit2af6dd77ea742d4ee911f466878624972929508a
tree241843c7c5376b9bcc948183c215c9837caa83bf
parent1e6267b335262eb6244c86a7102f00b26e57af4d
match.pd: Demote IFN_{ADD,SUB,MUL}_OVERFLOW operands [PR99591]

The overflow builtins work on infinite precision integers and then convert
to the result type's precision, so any argument promotions are useless.
The expand_arith_overflow expansion is able to demote the arguments itself
through get_range_pos_neg and get_min_precision calls and if needed promote
to whatever mode it decides to perform the operations in, but if there are
any promotions it demoted, those are already expanded.  Normally combine
would remove the useless sign or zero extensions when it sees the result
of those is only used in a lowpart subreg, but typically those lowpart
subregs appear multiple times in the pattern so that they describe properly
the overflow behavior and combine gives up, so we end up with e.g.
        movswl  %si, %esi
        movswl  %di, %edi
        imulw   %si, %di
        seto    %al
where both movswl insns are useless.

The following patch fixes it by demoting operands of the ifns (only gets
rid of integral to integral conversions that increase precision).
While IFN_{ADD,MUL}_OVERFLOW are commutative and just one simplify would be
enough, IFN_SUB_OVERFLOW is not, therefore two simplifications.

2021-09-02  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/99591
* match.pd: Demote operands of IFN_{ADD,SUB,MUL}_OVERFLOW if they
were promoted.

* gcc.target/i386/pr99591.c: New test.
* gcc.target/i386/pr97950.c: Match or reject setb or jn?b instructions
together with seta or jn?a.
gcc/match.pd
gcc/testsuite/gcc.target/i386/pr97950.c
gcc/testsuite/gcc.target/i386/pr99591.c [new file with mode: 0644]