<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108331>108331</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Possible Partial redundancy optimization using code duplication
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anirudha-commits
</td>
</tr>
</table>
<pre>
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](https://github.com/user-attachments/assets/9210830d-f693-4f8c-9d84-9d42ff53d1aa)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVMGO2zYQ_RrqMpAhjiVbOuiw8dbtqQhy66kYkSOLLUW6JGU3-fqCsut4i02ABhAkash5fHxvhhSjOTnmXjQfRPNa0JImH3pyJix6olL5eTYpFoPXn_uDd9FoDpAmE0FRZFG9iupF7Kr7s_6aEQS2yjttkvFOCuxuE3CQtwHbf1PhgPeQ02DGO957MPj_Yd7S-tVf4cow0YWB4ExpguvEgR_BwHpxmpz6DH6Eg8zTDgafJniwiECBIYWFN_CLv_KFA1h7mcFEWBwNliF58OdkZvOFb0KR06D8fF4SxwxLJzJuAz97PXibgP-m-WxZbF9gSukcxfZF4FHg8XRbsPHhJPD4ReDRXX77a68V87NOB7sMg3EnSBM_E43eXjjeKJyDHyzPP2gXwLe9gK-rnuyAhyEAz5a849j3sN-FfiS-Af6278Y91SseVpkuZBfOIQcDQ0w-sAbjIPDJxMQhbm65n3jM5e4hssrkAPOqtzZdr9fNEMi4PymkjfKzwCOFZJRlgcePeUi2_PQorvIna2bjKOP93squEXiE0QdgS4MPazwXw_0wKEXzwcx0YtG8Cmz_UyMmTctw33WJHEpKidQ0s0sxE4mR10GHsmq3lS7HXbct67FVZafbuux0jePYbLUkeij__C50v9XdtqOCe7nHnZQtdvti6vVe6UYNsuEBla40MakWWxzrgZh4X5geK6yrTmLVyFbuN129q9umqXiUcsQdibrimYzd5A7KZV6YGBfuM9OtLCwNbON6MyE6vsI6KxDzRRX6nFQOyymKurImpvgVJplkuf_oYzS5I-8evGnwW4euYsMSc_sorxn0crZGreFiCbb_jtp5t_unPAf_B6sk8LhyzILfD3Hp8Z8AAAD__8JLpsI">