-
-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Unnecessary compares and branches in asm output #45459
Copy link
Copy link
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Description
Activity
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
https://godbolt.org/g/62GNZf
In f1, the lines
cmp qword ptr [rdi + 16], 0andje .LBB0_2should be optimized away, but aren't, why?(It sets the len to 0 if it's not 0, otherwise leaves it at 0. The len will be 0 afterwards either way, so it should eliminate the check and just set it to 0 like
set_len(0).)I thought I'd open this issue because I don't think such optimization opportunities should be left on the table because it accumulatively affects a lot of code.