Commit 43e4b11
committed
[InstComb] Fold inttoptr (add (ptrtoint %B), %O) -> GEP for ICMP users.
Replace inttoptr (add (ptrtoint %B), %O) with (getelementptr i8, %B, %o)
if all users are ICmp instruction, which in turn means only the address
value is compared. We should be able to do this, if the src pointer,
the integer type and the destination pointer types have the same
bitwidth and address space.
A common source of such (inttoptr (add (ptrtoint %B), %O)) is from
various iterations in libc++.
In practice this triggers in a number of files in Clang and various open
source projects, including cppcheck, diamond, llama and more.
Alive2 Proof with constant offset: https://alive2.llvm.org/ce/z/K_5N_B1 parent 32a5adb commit 43e4b11
File tree
2 files changed
+23
-13
lines changed- llvm
- lib/Transforms/InstCombine
- test/Transforms/InstCombine
2 files changed
+23
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2072 | 2072 | | |
2073 | 2073 | | |
2074 | 2074 | | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
2075 | 2091 | | |
2076 | 2092 | | |
2077 | 2093 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 35 | + | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
181 | 179 | | |
182 | 180 | | |
183 | 181 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 182 | + | |
| 183 | + | |
188 | 184 | | |
189 | 185 | | |
190 | 186 | | |
| |||
204 | 200 | | |
205 | 201 | | |
206 | 202 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
212 | 206 | | |
213 | 207 | | |
214 | 208 | | |
| |||
0 commit comments