https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121168
Bug ID: 121168 Summary: missed optimization with ubsan at -O3 Product: gcc Version: 14.2.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Blocks: 121165 Target Milestone: --- Take: ``` int f1(int a, char *p) { char y = 0; __SIZE_TYPE__ ttt = a != 0; if (ttt == 1) __builtin_memmove(&y, p, ttt); return y; } int f(int a, char *p) { __SIZE_TYPE__ t = 1; __SIZE_TYPE__ t1 = 0; char y = 0; __SIZE_TYPE__ *tt; if (a) tt = &t; else tt = &t1; __SIZE_TYPE__ ttt = *tt; if (ttt == 1) __builtin_memmove(&y, p, ttt); return y; } ``` These 2 functions should have the same code generation with `-O3 -fsanitize=undefined` but f produces worse code due to phiprop not handling the prop here because of UBSAN_NULL but UBSAN_NULL expands to nothing for tt. Note this shows up in complex C++ code is not as simple asking folks not to write code like this. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121165 [Bug 121165] false positive Warray-bounds while building openmpt with -O3 -fsanitize=undefined