https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99309
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- In particular, we have: step.val = 610334368; and _1 = m.val; _2 = __builtin_constant_p (_1); before inline, and inline assumes that this __builtin_constant_p will evaluate to true. It will, but only if SRA optimizes it, e.g. fre5 can't do it. So after inlining we have: step.val = 610334368; ... m = step; _12 = m.val; _13 = __builtin_constant_p (_12); and if _13 is 0, there is __builtin_unreachable (); added by the inliner. where the latter chunk is in a loop, but nothing ever modifies step. Now, with -O1 it works fine, the __builtin_constant_p is kept until sra pass which optimizes that to step$val_2 = 610334368; ... m$val_1 = step$val_2; _12 = m$val_1; _13 = __builtin_constant_p (_12); and dom2 afterwards optimizes that. But, with -O2, vrp1 comes before sra and folds __builtin_constant_p to 0 because it still is not a constant. One bug is that IPA/inliner should not make assumptions what the following optimizations will do, it can make some optimistic assumptions during cost computation, but it should be prepared that the optimizations it relies on can be disabled, or just not doing its job for whatever other reason. Unless IPA wants to do that optimization by itself, i.e. propagate the constants there. But it really shouldn't do that just for __builtin_constant_p that guards something, but also for any other uses of the same reference, otherwise code guarded with __builtin_constant_p check could resolve that check to 1, but the uses of the argument elsewhere in the expressions actually would be non-constant. Another is that perhaps FRE/sccvn should be able to look the memory. I believe sccvn has code to handle step.val = 610334368; ... _12 = step.val; already, so it is just the extra m = step; copy in between that probably prevents it from working. Could sccvn remember for the aggregate copies that instead of looking at vara for value look at varb for value (with checks for invalidation), or just copy over all individual pieces on the aggrecate copy?