Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: "Nuno Lopes" Newsgroups: comp.compilers Subject: RE: Undefined Behavior Optimizations in C Date: Thu, 5 Jan 2023 10:24:13 -0000 Organization: Compilers Central Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-01-010@comp.compilers> References: <23-01-009@comp.compilers> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="50911"; mail-complaints-to="abuse@iecc.com" Keywords: semantics, optimize Posted-Date: 05 Jan 2023 11:52:36 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Content-Language: en-gb Xref: csiph.com comp.compilers:3279 Hi Lucian, I've a fair bit of experience with UB-related optimizations in LLVM. I don't think the speedup and code size reduction (also important) from certain UB exploitation is negligible. I think a better project would be to quantify the impact of each of the UB features. As a counter argument to your thesis, see the slides of my presentation "Semantics for Compiler IRs: Undefined Behavior is not Evil!": https://web.ist.utl.pt/nuno.lopes/pres/ub-vmcai19.pptx See an example here that gives a 39% speedup in a loop: https://web.ist.utl.pt/nuno.lopes/pres/poison-llvm16.pptx More data on how alias analysis loves UB: https://web.ist.utl.pt/nuno.lopes/pres/ub-vmcai19.pptx There's a key implementation difficulty in doing your study. While it's feasible to disable most UB exploitation at the clang side (not with compiler switches, you need to change the code). At the LLVM side is trickier to do a fair comparison. Because optimizations themselves produce UB code, but that's fine; it's just their way of expressing invariants. But then you cannot distinguish between what's an invariant and what's an exploitation of UB in the program. Don't get me wrong, I would be very keen to read such a study. But it's a lot more work than you think to do it right. Do ping me privately if you want more information/pointers. Nuno -----Original Message----- From: Lucian Popescu Sent: Thursday, January 5, 2023 10:06 AM Subject: Undefined Behavior Optimizations in C Hi, I'm currently working on an academic project that analyzes the speedup gain of Undefined Behavior Optimizations in C. I argue that UB Optimizations introduce more risks than actual speedup gains. This happens because most of the time the compiler does not have the context to understand the intention of the programmer in code that contains UB. ...