https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104645
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 52725 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52725&action=edit gcc12-pr104645.patch I wonder if at least for GCC 13 we just can't treat even that cast stmt as a preparation statement. This won't handle say shifts etc. with casts after them, but will at least fix this regression. And for GCC 13 perhaps we can throw away all the separation of "preparation" and assign statements and natural_element_p and absorbing_element_p and instead just try to constant evaluate all the middle_bb statements and see if that doesn't trigger traps/overflows/other UB and yields the expected PHI arg constant from the original comparison constant.