Commit 3a0a0c2
committed
VT: don't create undef in isBytewiseValue
The original motivation for this patch derives from a correctness issue
found in MemCpyOpt's fca2memcpy.ll test by Alive2. The output from
Alive2 is reproduced below:
----------------------------------------
define void @addrproducer(ptr %src, ptr %dst) {
%#1 = load {ptr, i8, i24, i32}, ptr %src, align 8
store {ptr, i8, i24, i32} undef, ptr %dst, align 8
%dst2 = gep ptr %dst, 16 x i64 1
store {ptr, i8, i24, i32} %#1, ptr %dst2, align 8
ret void
}
=>
define void @addrproducer(ptr %src, ptr %dst) {
%dst2 = gep ptr %dst, 16 x i64 1
memmove ptr %dst2 align 8, ptr %src align 8, i64 16
memset ptr %dst align 8, i8 undef, i64 16
ret void
}
Transformation doesn't verify! (unsound)
ERROR: Mismatch in memory
Example:
ptr %src = pointer(non-local, block_id=1, offset=0) / Address=#x08
ptr %dst = pointer(non-local, block_id=1, offset=0) / Address=#x08
Source:
{ptr, i8, i24, i32} %#1 = { poison, poison, poison, poison }
ptr %dst2 = pointer(non-local, block_id=1, offset=16) / Address=#x18
SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 1 alloc type: 0 alive: false
address: 0
Block 1 > size: 71 align: 1 alloc type: 0 alive:
true address: 8
Block 2 > size: 0 align: 2 alloc type: 0 alive: true
address: 4
Block 3 > size: 0 align: 1 alloc type: 0 alive: true
address: 4
Target:
ptr %dst2 = pointer(non-local, block_id=1, offset=16) / Address=#x18
Mismatch in pointer(non-local, block_id=1, offset=0)
Source value: null, byte offset=0
Target value: #x01
----------------------------------------
The underlying problem is in llvm::isBytewiseValue(), which creates and
returns an UndefValue when called with an UndefValue, and this result is
used by MemCpyOpt, leading to an incorrect optimization. Generally
speaking, reasoning about undef values when optimizing is tricky, and
considering that undef is scheduled for removal, change the function to
bail out on undef values, handle poison instead, and create a poison
value for all other purposes. Auding the callers of this function
reveals that MemCpyOpt is the only caller that explicitly checks the
return value of this function against undef: change this as well.
This patch has the nice side-effect of cleaning up some undefs in the
tests of MemCpyOpt and the unittests of ValueTracking.1 parent cb4433b commit 3a0a0c2
File tree
7 files changed
+66
-63
lines changed- llvm
- include/llvm/Analysis
- lib
- Analysis
- Transforms/Scalar
- test/Transforms/MemCpyOpt
- unittests/Analysis
7 files changed
+66
-63
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
621 | | - | |
| 620 | + | |
622 | 621 | | |
623 | 622 | | |
624 | 623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6163 | 6163 | | |
6164 | 6164 | | |
6165 | 6165 | | |
6166 | | - | |
6167 | | - | |
| 6166 | + | |
| 6167 | + | |
| 6168 | + | |
| 6169 | + | |
| 6170 | + | |
| 6171 | + | |
6168 | 6172 | | |
6169 | | - | |
| 6173 | + | |
6170 | 6174 | | |
6171 | | - | |
| 6175 | + | |
6172 | 6176 | | |
6173 | | - | |
| 6177 | + | |
6174 | 6178 | | |
6175 | 6179 | | |
6176 | 6180 | | |
| |||
6228 | 6232 | | |
6229 | 6233 | | |
6230 | 6234 | | |
6231 | | - | |
| 6235 | + | |
6232 | 6236 | | |
6233 | | - | |
| 6237 | + | |
6234 | 6238 | | |
6235 | 6239 | | |
6236 | 6240 | | |
6237 | 6241 | | |
6238 | 6242 | | |
6239 | | - | |
| 6243 | + | |
6240 | 6244 | | |
6241 | 6245 | | |
6242 | 6246 | | |
6243 | 6247 | | |
6244 | 6248 | | |
6245 | 6249 | | |
6246 | 6250 | | |
6247 | | - | |
| 6251 | + | |
6248 | 6252 | | |
6249 | 6253 | | |
6250 | 6254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
422 | | - | |
| 421 | + | |
| 422 | + | |
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2769 | 2769 | | |
2770 | 2770 | | |
2771 | 2771 | | |
2772 | | - | |
2773 | | - | |
| 2772 | + | |
| 2773 | + | |
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| |||
2789 | 2789 | | |
2790 | 2790 | | |
2791 | 2791 | | |
2792 | | - | |
2793 | | - | |
| 2792 | + | |
| 2793 | + | |
2794 | 2794 | | |
2795 | 2795 | | |
2796 | 2796 | | |
| |||
2869 | 2869 | | |
2870 | 2870 | | |
2871 | 2871 | | |
2872 | | - | |
| 2872 | + | |
2873 | 2873 | | |
2874 | 2874 | | |
2875 | 2875 | | |
2876 | | - | |
2877 | | - | |
| 2876 | + | |
| 2877 | + | |
2878 | 2878 | | |
2879 | 2879 | | |
2880 | | - | |
| 2880 | + | |
2881 | 2881 | | |
2882 | 2882 | | |
2883 | 2883 | | |
2884 | | - | |
2885 | | - | |
| 2884 | + | |
| 2885 | + | |
2886 | 2886 | | |
2887 | 2887 | | |
2888 | 2888 | | |
2889 | 2889 | | |
2890 | 2890 | | |
2891 | 2891 | | |
2892 | | - | |
2893 | | - | |
| 2892 | + | |
| 2893 | + | |
2894 | 2894 | | |
2895 | 2895 | | |
2896 | 2896 | | |
| |||
2910 | 2910 | | |
2911 | 2911 | | |
2912 | 2912 | | |
2913 | | - | |
| 2913 | + | |
2914 | 2914 | | |
2915 | 2915 | | |
2916 | 2916 | | |
2917 | 2917 | | |
2918 | 2918 | | |
2919 | 2919 | | |
2920 | | - | |
2921 | | - | |
| 2920 | + | |
| 2921 | + | |
2922 | 2922 | | |
2923 | 2923 | | |
2924 | 2924 | | |
| |||
2938 | 2938 | | |
2939 | 2939 | | |
2940 | 2940 | | |
2941 | | - | |
| 2941 | + | |
2942 | 2942 | | |
2943 | 2943 | | |
2944 | 2944 | | |
2945 | 2945 | | |
2946 | 2946 | | |
2947 | 2947 | | |
2948 | | - | |
2949 | | - | |
| 2948 | + | |
| 2949 | + | |
2950 | 2950 | | |
2951 | 2951 | | |
2952 | 2952 | | |
| |||
2959 | 2959 | | |
2960 | 2960 | | |
2961 | 2961 | | |
2962 | | - | |
| 2962 | + | |
2963 | 2963 | | |
2964 | 2964 | | |
2965 | 2965 | | |
2966 | | - | |
2967 | | - | |
| 2966 | + | |
| 2967 | + | |
2968 | 2968 | | |
2969 | 2969 | | |
2970 | | - | |
| 2970 | + | |
2971 | 2971 | | |
2972 | 2972 | | |
2973 | 2973 | | |
2974 | | - | |
2975 | | - | |
| 2974 | + | |
| 2975 | + | |
2976 | 2976 | | |
2977 | 2977 | | |
2978 | 2978 | | |
2979 | 2979 | | |
2980 | 2980 | | |
2981 | 2981 | | |
2982 | | - | |
2983 | | - | |
| 2982 | + | |
| 2983 | + | |
2984 | 2984 | | |
2985 | 2985 | | |
2986 | 2986 | | |
2987 | | - | |
| 2987 | + | |
2988 | 2988 | | |
2989 | 2989 | | |
2990 | 2990 | | |
2991 | | - | |
| 2991 | + | |
2992 | 2992 | | |
2993 | 2993 | | |
2994 | 2994 | | |
| |||
0 commit comments