https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103171
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Martin Jambor <jamb...@gcc.gnu.org>: https://gcc.gnu.org/g:f6d65e803623c7ba6c8eb92ce5975fc1b90cd91e commit r12-7936-gf6d65e803623c7ba6c8eb92ce5975fc1b90cd91e Author: Martin Jambor <mjam...@suse.cz> Date: Thu Mar 31 16:50:24 2022 +0200 ipa: Create LOAD references when necessary during inlining (PR 103171) in r12-2523-g13586172d0b70c ipa-prop tracking of jump functions during inlining got the ability to remove ADDR references when inlining discovered that they were not necessary or turn them into LOAD references when we know that what was a function call argument passed by reference will end up as a load (one or more). Unfortunately, the code only creates the LOAD references when replacing removed ADDR references and PR 103171 showed that with some ordering of inlining, we need to add the LOAD reference before we know we can remove the ADDR one - or the reference will be lost, leading to link errors or even ICEs. Specifically in testcase gcc.dg/lto/pr103171_1.c added in this patch, if foo() is inlined to entry(), we need to create the LOAD reference so that when later bar() is inlined into foo() and we discover that the paameter is unused, we can remove the ADDR reference and still keep the varaible around for the load. Martin gcc/ChangeLog: 2022-01-28 Martin Jambor <mjam...@suse.cz> PR ipa/103171 * ipa-prop.cc (propagate_controlled_uses): Add a LOAD reference always when an ADDR_EXPR constant is known to reach a load because of inlining, not just when removing an ADDR reference. gcc/testsuite/ChangeLog: 2022-01-28 Martin Jambor <mjam...@suse.cz> PR ipa/103171 * gcc.dg/ipa/remref-6.c: Adjust dump scan string. * gcc.dg/ipa/remref-7.c: New test. * gcc.dg/lto/pr103171_0.c: New test. * gcc.dg/lto/pr103171_1.c: Likewise.