Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Partial redundancy optimization using code duplication #108331

Open
anirudha-commits opened this issue Sep 12, 2024 · 0 comments
Open

Possible Partial redundancy optimization using code duplication #108331

anirudha-commits opened this issue Sep 12, 2024 · 0 comments

Comments

@anirudha-commits
Copy link

Consider this case

if (condition1)
 C1
else
 C2
end if

if (condition2)
 C1
else
 C2
end if

Now we have a path where we have redundancy of C1 when both conditions are true. However llvm is unable to optimize this and computes C1 again. Godbolt example: https://godbolt.org/z/nvYq7dcee

Clubbing the conditions solves this problem

if (condition1)
 C1
  if (condition2)
   C1
  else
   C2
  end if
else
 C2
 if (condition2)
  C1
 else
  C2
 end if
end if

in this case, the values can be stored in registers.
Refer to section 2 in https://www.brainkart.com/article/Partial-Redundancy-Elimination_8195/ for elaboration:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants