On Sat, 2 Nov 2024, Sam James wrote:
> Some references to feed discussion which I had in my logs from > discussing it with someone the other week after that interaction we > had with alanc: > * https://github.com/llvm/llvm-project/issues/28790 (not very > insightful, other than to show it has a history of confusing people, but > one might argue that for other (definitely-valid) optimisations) > * https://github.com/llvm/llvm-project/issues/49826 > * https://github.com/llvm/llvm-project/issues/51476 Thank you. I believe in this situation the onus is on us to prove that such transforms are correct. Exhibit A: POSIX semantics for malloc involve errno. Exhibit B: malloc is supposed to give unique pointers (without any intervening free's). However, the proposed patch should be powerful enough to transform void f() { void *p = __builtin_malloc(1); if (p) { asm(""); f(); } __builtin_free(p); } to an infinite loop, but infinite amout of unique pointers is impossible. In a similar vein, five mallocs, each allocating a quarter of address space, also seems impossible. I am reminded that we take a pretty strict stance against enabling -fno-math-errno -fno-trapping-math, even though they gate a lot of useful vectorization. So it's a bit weird we're going so gung-ho with this malloc elimination. Alexander