Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Spiros Bousbouras Newsgroups: comp.compilers Subject: Re: Undefined Behavior Optimizations in C Date: Thu, 5 Jan 2023 18:06:53 -0000 (UTC) Organization: A noiseless patient Spider Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-01-011@comp.compilers> References: <23-01-009@comp.compilers> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="65170"; mail-complaints-to="abuse@iecc.com" Keywords: optimize, semantics Posted-Date: 05 Jan 2023 13:13:05 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <23-01-009@comp.compilers> X-Organisation: Weyland-Yutani Xref: csiph.com comp.compilers:3280 On 5 Jan 2023 10:05:49 +0000 "Lucian Popescu" wrote: > 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. For example this fast inverse square root > function [1] triggers UB at this line: i = * ( long * ) &y;. A "smart" > compiler could delete this line as an optimization because it contains UB. > > Don't get me wrong, I'm not saying that the compiler should magically > understand situations where the programmer makes UB mistakes and then > repair them. What I'm saying is that the compiler should compile the code > "as is" without making smart optimization transformations that break the > intention of the programmer. Do you have a rigorous definition of what it means for a compiler to compile the code "as is" without making smart optimization transformations that break the intention of the programmer. ? Without such a definition , I don't think you are making a meaningful distinction and I think it would be hard to impossible to come up with such a definition. > To test the theory that the UB Optimizations introduce more risks than > speedup gains, Isn't this comparing apples and oranges ? > I take OpenBSD (for its focus on security and robustness) and compile it on > one hand with UB Optimizations turned on and with UB Optimizations turned > off. If I will find out that the speedup gain is not so big (I don't know > what big means at the moment) then the UB Optimizations don't make sense in > the OS. Otherwise, it means that I was wrong, but I will still want to see > what security risks they introduce on the respective OS setup. Given the large variety of tasks that an operating system can be used for , I'm curious to see what you are going to test on OpenBSD to determine speedup gain. I think it would make more sense to test with chess engines : prepare a collection of chess positions and see how many nodes per second an engine can calculate for a given position depending on how the engine was compiled. Doing analogous experiments with graphics code or numerical analysis code would also be interesting. But an operating system , I don't know , it seems too general. > My current progress is here [2]. I did not start the technical work, ATM I only > have the research proposal. I reached you to see if you have any feedback > on this proposal. Is it a manageable goal? Do you see ways in which it can > be improved? Does it suck? etc, etc. > > Lucian Popescu > > [1] https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code > [2] https://tildegit.org/lucic71/dissertation/src/branch/master/TSW/tsw.pdf