aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-01-04 12:16:22 +0100
committerJakub Jelinek <jakub@redhat.com>2023-01-04 12:16:22 +0100
commitebc449119442501c927ede0e83697eaece72223e (patch)
tree229d0671534b2446b2ae1b945a01e99d580c95fd /gcc/tree-vrp.cc
parent345dffd0d4ebff7e705dfff1a8a72017a167120a (diff)
downloadgcc-ebc449119442501c927ede0e83697eaece72223e.zip
gcc-ebc449119442501c927ede0e83697eaece72223e.tar.gz
gcc-ebc449119442501c927ede0e83697eaece72223e.tar.bz2
vrp: Handle pointers in maybe_set_nonzero_bits [PR108253]
maybe_set_nonzero_bits calls set_nonzero_bits which asserts that var doesn't have pointer type. While we could punt for those cases, I think we can handle at least some easy cases. Earlier in maybe_set_nonzero_bits we've checked this is on (var & cst) == 0 edge and the other edge is __builtin_unreachable, so if cst is say 3 as in the testcase, we want to turn it into 4 byte alignment of the pointer. 2023-01-04 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/108253 * tree-vrp.cc (maybe_set_nonzero_bits): Handle var with pointer types. * g++.dg/opt/pr108253.C: New test.
Diffstat (limited to 'gcc/tree-vrp.cc')
-rw-r--r--gcc/tree-vrp.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 0dfea5a..3c43176 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -789,8 +789,22 @@ maybe_set_nonzero_bits (edge e, tree var)
return;
}
cst = gimple_assign_rhs2 (stmt);
- set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var),
- wi::to_wide (cst)));
+ if (POINTER_TYPE_P (TREE_TYPE (var)))
+ {
+ struct ptr_info_def *pi = SSA_NAME_PTR_INFO (var);
+ if (pi && pi->misalign)
+ return;
+ wide_int w = wi::bit_not (wi::to_wide (cst));
+ unsigned int bits = wi::ctz (w);
+ if (bits == 0 || bits >= HOST_BITS_PER_INT)
+ return;
+ unsigned int align = 1U << bits;
+ if (pi == NULL || pi->align < align)
+ set_ptr_info_alignment (get_ptr_info (var), align, 0);
+ }
+ else
+ set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var),
+ wi::to_wide (cst)));
}
/* Searches the case label vector VEC for the index *IDX of the CASE_LABEL