https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110515
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- So IMHO it's the fault of invariant motion moving _145 = MEM[(struct LargeRep *)&Visited + 8B].Slots; and _34 = MEM[(struct LargeRep *)&Visited + 8B].Capacity; out of loop 10 as these loads are executed conditional. They are know to not trap and that's why LIM doesn't require them unconditionally executed but as we can see here CSE later takes advantage of undefinedness if there's a load using the wrong TBAA type not matching the dynamic type of the storage. For example char storage[4] __attribute__((aligned(4))); double foo (int n, int kind) { double res; for (int i = 0; i < n; ++i) if (kind) res = *(int *)storage; else res = *(float *)storage; return res; } is transformed to <bb 2> [local count: 118111600]: if (n_7(D) > 0) goto <bb 8>; [89.00%] else goto <bb 7>; [11.00%] <bb 8> [local count: 105119324]: _2 = MEM[(float *)&storage]; _1 = MEM[(int *)&storage]; <bb 3> [local count: 955630225]: # i_16 = PHI <i_13(9), 0(8)> if (kind_10(D) != 0) goto <bb 4>; [50.00%] else goto <bb 5>; [50.00%] <bb 4> [local count: 477815112]: res_12 = (double) _1; goto <bb 6>; [100.00%] <bb 5> [local count: 477815112]: res_11 = (double) _2; <bb 6> [local count: 955630225]: # res_3 = PHI <res_12(4), res_11(5)> i_13 = i_16 + 1; if (n_7(D) > i_13) goto <bb 9>; [89.00%] else goto <bb 7>; [11.00%] <bb 9> [local count: 850510901]: goto <bb 3>; [100.00%] <bb 7> [local count: 118111600]: # res_15 = PHI <res_3(6), res_6(D)(2)> return res_15; and then eventually to the following, unconditionally using float as alias set. <bb 2> [local count: 118111600]: if (n_7(D) > 0) goto <bb 3>; [89.00%] else goto <bb 6>; [11.00%] <bb 3> [local count: 105119324]: _2 = MEM[(float *)&storage]; if (kind_10(D) != 0) goto <bb 4>; [50.00%] else goto <bb 5>; [50.00%] <bb 4> [local count: 52559662]: _4 = VIEW_CONVERT_EXPR<int>(_2); res_12 = (double) _4; goto <bb 6>; [100.00%] <bb 5> [local count: 52559662]: res_11 = (double) _2; <bb 6> [local count: 118111600]: # res_15 = PHI <res_11(5), res_6(D)(2), res_12(4)> return res_15;