[PATCH] D86844: [LoopDeletion] Allows deletion of possibly infinite side-effect free loops
Dávid Bolvanský via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 7 09:07:04 PST 2021
xbolva00 added a comment.
In D86844#2484639 <https://reviews.llvm.org/D86844#2484639>, @atmnpatel wrote:
> In D86844#2484568 <https://reviews.llvm.org/D86844#2484568>, @fhahn wrote:
>
>> In D86844#2481922 <https://reviews.llvm.org/D86844#2481922>, @xbolva00 wrote:
>>
>>> int a, b;
>>>
>>> int f(void) {
>>> while (1) {
>>> if (a != b) return 1;
>>> }
>>> return 0;
>>> }
>>>
>>> int g(int a, int b) {
>>> while (1) {
>>> if (a != b) return 1;
>>> }
>>> return 0;
>>> }
>>>
>>> LLVM does not catch these cases; gcc does.
>>>
>>> https://godbolt.org/z/jW7son
>>
>> Looks like `must progress` does not get added? If it gets added to the IR the loops get removed: https://godbolt.org/z/77v17P
>
> I might be misunderstanding the standard here but since 1 is a non-zero constant expression, it can't be assumed to terminate by the implementation right? The relevant section from C11 at least is "An iteration statement whose controlling expression is not a constant expression that performs [explanation of what it deems as progress] may be assumed by the implementation to terminate" (C11 6.8.5 p6). I think these cases fall outside of the scope of this particular change ...
For C yes, but are there such rules for C++? GCC in c++ mode does not check for non-zero constant expr and happily performs this optimization.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86844/new/
https://reviews.llvm.org/D86844
More information about the cfe-commits
mailing list