tree-optimization/114502 - final value replacement for idempotent negation #206

Open
Rachit wants to merge 1 commit from Rachit/gcc:PR-114502 into trunk
Member

SCEV cannot represent a period-2 recurrence, so recognize loops of the
form 'c = -c' with a constant trip count in the final-value replacement
and replace the exit value by c or -c depending on the parity of the trip
count. Bail out when signed overflow must trap (-ftrapv) or be sanitized,
mirroring the existing bitop special-cases.

Tested on aarch64-linux-gnu: gcc.dg/tree-ssa/scev-negate-{1,2,3}.c all pass.

PR tree-optimization/114502
gcc/ChangeLog:

	* tree-scalar-evolution.cc (analyze_and_compute_negate_effect): New.
	(final_value_replacement_loop): Call it.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/scev-negate-1.c: New test.
	* gcc.dg/tree-ssa/scev-negate-2.c: New test.
	* gcc.dg/tree-ssa/scev-negate-3.c: New test.

Signed-off-by: Rachit Mehta rachit.mehta@oss.qualcomm.com

CC: andrew.pinski@oss.qualcomm.com

SCEV cannot represent a period-2 recurrence, so recognize loops of the form 'c = -c' with a constant trip count in the final-value replacement and replace the exit value by c or -c depending on the parity of the trip count. Bail out when signed overflow must trap (-ftrapv) or be sanitized, mirroring the existing bitop special-cases. Tested on aarch64-linux-gnu: gcc.dg/tree-ssa/scev-negate-{1,2,3}.c all pass. PR tree-optimization/114502 ``` gcc/ChangeLog: * tree-scalar-evolution.cc (analyze_and_compute_negate_effect): New. (final_value_replacement_loop): Call it. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/scev-negate-1.c: New test. * gcc.dg/tree-ssa/scev-negate-2.c: New test. * gcc.dg/tree-ssa/scev-negate-3.c: New test. ``` Signed-off-by: Rachit Mehta <rachit.mehta@oss.qualcomm.com> CC: andrew.pinski@oss.qualcomm.com
Member

Hi @Rachit. This bot helps send your PR as a patch series to the mailing list.

Next steps

  1. Write a clear PR description. It will be used as the cover letter.
  2. To CC extra people, add lines like this at the end of the PR description: CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>.
  3. To preview the emails, comment with /preview.
  4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with /submit.
  5. Use the cover-letter links below to follow replies.
  6. For a new patch series, push your changes, update the PR description with a Changes since vX section, and comment with /submit again.

See Submitting Patches and UsingForge.

Consider joining the gcc and gcc-patches mailing lists..
For real time communication, check the gcc irc channels.

Or join #overseers on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).

<!-- pr-welcome --> Hi @Rachit. This bot helps send your PR as a patch series to the mailing list. ## Next steps 1. Write a clear PR description. It will be used as the cover letter. 2. To CC extra people, add lines like this **at the end** of the PR description: `CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>`. 3. To preview the emails, comment with `/preview`. 4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with `/submit`. 5. Use the cover-letter links below to follow replies. 6. For a new patch series, push your changes, update the PR description with a `Changes since vX` section, and comment with `/submit` again. See [Submitting Patches](https://gcc.gnu.org/contribute.html#patches) and [UsingForge](https://gcc.gnu.org/wiki/UsingForge). Consider joining the [gcc and gcc-patches mailing lists.](https://gcc.gnu.org/lists.html). For real time communication, check the [gcc irc channels](https://gcc.gnu.org/wiki/GCConIRC). Or join [`#overseers`](https://web.libera.chat/#overseers) on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).
Rachit force-pushed PR-114502 from f4ed39865e
All checks were successful
/ format-checks (pull_request) Successful in 1m35s
to 7bda01c9f0
All checks were successful
/ format-checks (pull_request) Successful in 1m30s
2026-07-31 04:41:10 +00:00
Compare
Author
Member

/preview

/preview
Member

Sent patch series version 1 containing 1 patches to @Rachit's email address.
Message Id of cover message is <bmm.hl37e3q6mi.gcc.gcc.Rachit.206.1.0@forge-stage.sourceware.org>.

Sent patch series version 1 containing 1 patches to @Rachit's email address. Message Id of cover message is `<bmm.hl37e3q6mi.gcc.gcc.Rachit.206.1.0@forge-stage.sourceware.org>`.
Author
Member

/submit

/submit
Member

Version 1 of this pull request has been stored. It includes the following commits:

  • tree-optimization/114502 - final value replacement for idempotent negation - 7bda01c9f0
<!-- pr-new-version --> Version 1 of this pull request has been stored. It includes the following commits: - tree-optimization/114502 - final value replacement for idempotent negation - 7bda01c9f0fd3d2a364363a351cfec966b0bb511
Member

Pull Request versions:

# Base Head
1 e873aac49e 7bda01c9f0 (diff)

In order to compare , clone this repository and run

PR=206
git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*"
PRV1=1
PRV2=2
git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head"  "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head"
<!-- pr-versions --> Pull Request versions: | # | Base | Head | | | - | ---- | ---- | - | | 1 | e873aac49eb2b58ae18e05f4150826278bdbb3cb | 7bda01c9f0fd3d2a364363a351cfec966b0bb511 | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/e873aac49eb2b58ae18e05f4150826278bdbb3cb...7bda01c9f0fd3d2a364363a351cfec966b0bb511) | In order to compare , clone this repository and run ``` PR=206 git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*" PRV1=1 PRV2=2 git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head" "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head" ```
Member

Sent patch series version 1 containing 1 patches to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd andrew.pinski@oss.qualcomm.com.
Cover letter

Sent patch series version 1 containing 1 patches to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd andrew.pinski@oss.qualcomm.com. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hl37nocx96.gcc.gcc.Rachit.206.1.0@forge-stage.sourceware.org)
All checks were successful
/ format-checks (pull_request) Successful in 1m30s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u PR-114502:Rachit-PR-114502
git switch Rachit-PR-114502

Merge

Merge the changes and update on Forgejo.
git switch trunk
git merge --no-ff Rachit-PR-114502
git switch Rachit-PR-114502
git rebase trunk
git switch trunk
git merge --ff-only Rachit-PR-114502
git switch Rachit-PR-114502
git rebase trunk
git switch trunk
git merge --no-ff Rachit-PR-114502
git switch trunk
git merge --squash Rachit-PR-114502
git switch trunk
git merge --ff-only Rachit-PR-114502
git switch trunk
git merge Rachit-PR-114502
git push origin trunk
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gcc/gcc!206
No description provided.