lower-bitint: Avoid overlap between destinations and sources in libgcc calls [PR113421]
commit9f8ba332e988fb582f6ca32465f6d65283f53b3a
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Jan 2024 13:43:40 +0000 (17 14:43 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 17 Jan 2024 13:43:40 +0000 (17 14:43 +0100)
treed15e786236838c5ed728b12e52080cff06ccf7bf
parenta98a24ac65c1a0ee598e5b54d9e4c921a9744a08
lower-bitint: Avoid overlap between destinations and sources in libgcc calls [PR113421]

The following testcase is miscompiled because the bitint lowering emits a
  .MULBITINT (&a, 1024, &a, 1024, &x, 1024);
call.  The bug is in the overlap between the destination and source, that is
something the libgcc routines don't handle, they use the source arrays
during the entire algorithms which computes the destination array(s).
For the mapping of SSA_NAMEs to VAR_DECLs the code already supports that
correctly, but the checking whether a load from memory can be used directly
without a temporary even when earlier we decided to merge the
multiplication/division/modulo etc. with a store didn't.

The following patch implements that.

2024-01-17  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/113421
* gimple-lower-bitint.cc (stmt_needs_operand_addr): Adjust function
comment.
(bitint_dom_walker::before_dom_children): Add g temporary to simplify
formatting.  Start at vop rather than cvop even if stmt is a store
and needs_operand_addr.

* gcc.dg/torture/bitint-50.c: New test.
gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/torture/bitint-50.c [new file with mode: 0644]