RE: Undefined Behavior Optimizations in C

"Nuno Lopes" <nuno.lopes@tecnico.ulisboa.pt>
Thu, 5 Jan 2023 10:24:13 -0000

          From comp.compilers

Related articles
Undefined Behavior Optimizations in C lucic71@ctrl-c.club (Lucian Popescu) (2023-01-05)
RE: Undefined Behavior Optimizations in C nuno.lopes@tecnico.ulisboa.pt (Nuno Lopes) (2023-01-05)
Re: Re: Undefined Behavior Optimizations in C jonathanchesterfield@gmail.com (Jon Chesterfield) (2023-01-10)
| List of all articles for this month |
From: "Nuno Lopes" <nuno.lopes@tecnico.ulisboa.pt>
Newsgroups: comp.compilers
Date: Thu, 5 Jan 2023 10:24:13 -0000
Organization: Compilers Central
References: 23-01-009
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
Content-Language: en-gb

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. ...


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.