diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-08-15 13:56:57 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-08-15 13:56:57 +0200 |
commit | 3a74a7bf62f47ed0d19866576378724be932ee17 (patch) | |
tree | 4ed5f3d89d7919549aa5e59a9a3a935c9cffb1ad /gcc/testsuite/g++.dg/abi | |
parent | 6624ad73064de241e937e97a28b65c50fe14c78e (diff) | |
download | gcc-3a74a7bf62f47ed0d19866576378724be932ee17.zip gcc-3a74a7bf62f47ed0d19866576378724be932ee17.tar.gz gcc-3a74a7bf62f47ed0d19866576378724be932ee17.tar.bz2 |
ifcvt: Fix up noce_convert_multiple_sets [PR106590]
The following testcase is miscompiled on x86_64-linux.
The problem is in the noce_convert_multiple_sets optimization.
We essentially have:
if (g == 1)
{
g = 1;
f = 23;
}
else
{
g = 2;
f = 20;
}
and for each insn try to create a conditional move sequence.
There is code to detect overlap with the regs used in the condition
and the destinations, so we actually try to construct:
tmp_g = g == 1 ? 1 : 2;
f = g == 1 ? 23 : 20;
g = tmp_g;
which is fine. But, we actually try to create two different
conditional move sequences in each case, seq1 with the whole
(eq (reg/v:HI 82 [ g ]) (const_int 1 [0x1]))
condition and seq2 with cc_cmp
(eq (reg:CCZ 17 flags) (const_int 0 [0]))
to rely on the earlier present comparison. In each case, we
compare the rtx costs and choose the cheaper sequence (seq1 if both
have the same cost).
The problem is that with the skylake tuning,
tmp_g = g == 1 ? 1 : 2;
is actually expanded as
tmp_g = (g == 1) + 1;
in seq1 (which clobbers (reg 17 flags)) and as a cmov in seq2
(which doesn't). The tuning says both have the same cost, so we
pick seq1. Next we check sequences for
f = g == 1 ? 23 : 20; and here the seq2 cmov is cheaper, but it
uses (reg 17 flags) which has been clobbered earlier.
The following patch fixes that by detecting if we in the chosen
sequence clobber some register mentioned in cc_cmp or rev_cc_cmp,
and if yes, arranges for only seq1 (i.e. sequences that emit the
comparison itself) to be used after that.
2022-08-15 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/106590
* ifcvt.cc (check_for_cc_cmp_clobbers): New function.
(noce_convert_multiple_sets_1): If SEQ sets or clobbers any regs
mentioned in cc_cmp or rev_cc_cmp, don't consider seq2 for any
further conditional moves.
* gcc.dg/torture/pr106590.c: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/abi')
0 files changed, 0 insertions, 0 deletions