Optimizing away empty loop with step

Johan j at j.nl
Sat Jul 31 12:07:49 UTC 2021


On Friday, 30 July 2021 at 10:09:55 UTC, David Nadlinger wrote:
> On 30 Jul 2021, at 10:58, Vladimir Panteleev via 
> digitalmars-d-ldc wrote:
>> My second guess was that the C compilers were happy with 
>> optimizing it away because signed integer overflow is 
>> undefined in C. But, changing the type to unsigned didn't make 
>> a difference.
>
> LLVM/Clang 10 didn't optimise it away for me with everything 
> made unsigned. Clang trunk on Godbolt does, but that's because 
> it makes use of the fact that infinite loops are UB in C (as 
> encoded in the `mustprogress` function attribute).

Adding that attribute to the function indeed works, but requires 
LLVM 12:

https://d.godbolt.org/z/1Yb7YnP7e

-Johan



More information about the digitalmars-d-ldc mailing list