Commit 09b0885
authored
[LangRef] Specify icmp on pointers to only compare address (#163936)
This changes LangRef to specify that pointer icmp only compares the
address bits of the pointers. That is, `icmp pred %a, %b` is equivalent
to `icmp pred ptrtoaddr(%a), ptrtoaddr(%b)`.
Similarly, it specifies that the `nonnull` attribute requires that the
address bits are non-zero.
There are a couple of motivations for this:
* For inequality comparisons, this is really the only sensible
semantics. Relational comparison of address and metadata bits as a
single integer is generally meaningless (unless the metadata bits are
equal).
* This matches (as far as I understand) the behavior of existing CHERI
implementations.
* LLVM can only reason about the address bits. These semantics allow
pointers with non-address bits to receive essentially the same
comparison optimization support as ordinary pointers.
In terms of implementation, this PR adjusts:
* The AMDGPULowerBufferFatPointers pass.
* An InstCombine fold that may replace pointers with different
non-address bits.
* The fold that replaces pointers based on dominating pointer equality.
It does not adjust:
* ISel, because we don't have in-tree targets where we can show a
difference.
* Various icmp+ptrtoint transforms, because we'll have to change this
code for ptrtoaddr optimization support anyway, and these changes are
tightly related.
Related discussion starting from:
https://discourse.llvm.org/t/clarifiying-the-semantics-of-ptrtoint/83987/60?u=nikic1 parent 15d7c01 commit 09b0885
File tree
7 files changed
+34
-41
lines changed- llvm
- docs
- lib
- Analysis
- Target/AMDGPU
- Transforms/InstCombine
- test
- CodeGen/AMDGPU
- Transforms
- GVN
- InstCombine
7 files changed
+34
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1556 | 1556 | | |
1557 | 1557 | | |
1558 | 1558 | | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
1559 | 1562 | | |
1560 | 1563 | | |
1561 | 1564 | | |
| |||
13064 | 13067 | | |
13065 | 13068 | | |
13066 | 13069 | | |
13067 | | - | |
13068 | | - | |
| 13070 | + | |
| 13071 | + | |
| 13072 | + | |
| 13073 | + | |
13069 | 13074 | | |
13070 | 13075 | | |
13071 | 13076 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
806 | | - | |
| 806 | + | |
807 | 807 | | |
808 | 808 | | |
809 | 809 | | |
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
| 815 | + | |
| 816 | + | |
815 | 817 | | |
816 | 818 | | |
817 | | - | |
| 819 | + | |
818 | 820 | | |
819 | 821 | | |
820 | 822 | | |
| |||
842 | 844 | | |
843 | 845 | | |
844 | 846 | | |
845 | | - | |
| 847 | + | |
| 848 | + | |
846 | 849 | | |
847 | | - | |
| 850 | + | |
848 | 851 | | |
849 | 852 | | |
850 | 853 | | |
| |||
853 | 856 | | |
854 | 857 | | |
855 | 858 | | |
856 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
857 | 863 | | |
858 | 864 | | |
859 | 865 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2062 | 2062 | | |
2063 | 2063 | | |
2064 | 2064 | | |
2065 | | - | |
2066 | | - | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
2073 | | - | |
2074 | | - | |
2075 | | - | |
| 2065 | + | |
2076 | 2066 | | |
2077 | 2067 | | |
2078 | 2068 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3373 | 3373 | | |
3374 | 3374 | | |
3375 | 3375 | | |
3376 | | - | |
3377 | | - | |
3378 | | - | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
3379 | 3379 | | |
3380 | 3380 | | |
3381 | 3381 | | |
| |||
Lines changed: 5 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
410 | | - | |
| 408 | + | |
411 | 409 | | |
412 | 410 | | |
413 | 411 | | |
| |||
471 | 469 | | |
472 | 470 | | |
473 | 471 | | |
474 | | - | |
475 | | - | |
476 | | - | |
| 472 | + | |
477 | 473 | | |
478 | 474 | | |
479 | 475 | | |
| |||
487 | 483 | | |
488 | 484 | | |
489 | 485 | | |
490 | | - | |
491 | | - | |
492 | | - | |
| 486 | + | |
493 | 487 | | |
494 | 488 | | |
495 | 489 | | |
| |||
503 | 497 | | |
504 | 498 | | |
505 | 499 | | |
506 | | - | |
507 | | - | |
508 | | - | |
| 500 | + | |
509 | 501 | | |
510 | 502 | | |
511 | 503 | | |
| |||
519 | 511 | | |
520 | 512 | | |
521 | 513 | | |
522 | | - | |
523 | | - | |
524 | | - | |
| 514 | + | |
525 | 515 | | |
526 | 516 | | |
527 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
408 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
409 | 411 | | |
410 | 412 | | |
411 | 413 | | |
412 | | - | |
| 414 | + | |
413 | 415 | | |
414 | 416 | | |
415 | 417 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| |||
0 commit comments