Commit 29fe3fe
[InstSimplify] Peephole optimization for icmp (urem X, Y), X
This revision adds the following peephole optimization
and it's negation:
%a = urem i64 %x, %y
%b = icmp ule i64 %a, %x
====>
%b = true
With John Regehr's help this optimization was checked with Alive2
which suggests it should be valid.
This pattern occurs in the bound checks of Rust code, the program
const N: usize = 3;
const T = u8;
pub fn split_mutiple(slice: &[T]) -> (&[T], &[T]) {
let len = slice.len() / N;
slice.split_at(len * N)
}
the method call slice.split_at will check that len * N is within
the bounds of slice, this bounds check is after some transformations
turned into the urem seen above and then LLVM fails to optimize it
any further. Adding this optimization would cause this bounds check
to be fully optimized away.
ref: rust-lang/rust#74938
Differential Revision: https://reviews.llvm.org/D850921 parent b778b04 commit 29fe3fe
File tree
2 files changed
+12
-12
lines changed- llvm
- lib/Analysis
- test/Transforms/InstSimplify
2 files changed
+12
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2814 | 2814 | | |
2815 | 2815 | | |
2816 | 2816 | | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
2817 | 2825 | | |
2818 | 2826 | | |
2819 | 2827 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
728 | | - | |
729 | | - | |
730 | | - | |
| 728 | + | |
731 | 729 | | |
732 | 730 | | |
733 | 731 | | |
| |||
736 | 734 | | |
737 | 735 | | |
738 | 736 | | |
739 | | - | |
740 | | - | |
741 | | - | |
| 737 | + | |
742 | 738 | | |
743 | 739 | | |
744 | 740 | | |
| |||
747 | 743 | | |
748 | 744 | | |
749 | 745 | | |
750 | | - | |
751 | | - | |
752 | | - | |
| 746 | + | |
753 | 747 | | |
754 | 748 | | |
755 | 749 | | |
| |||
758 | 752 | | |
759 | 753 | | |
760 | 754 | | |
761 | | - | |
762 | | - | |
763 | | - | |
| 755 | + | |
764 | 756 | | |
765 | 757 | | |
766 | 758 | | |
| |||
0 commit comments