[llvm-dev] Loop optimization

Garba Peter via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 13 09:54:38 PDT 2019


Hi,

I was wondering if there is an optimization pass in LLVM or Polly that can optimize this given loop:


int main(int argc, char* argv[]) {
                char s = 0;

                // Loop is setting s = argv[1][0];
                for (int i=0; i<argv[1][0]; i++) {
                    s++;
                }

                printf("s = %c\n", s);

                return 0;
}


into:

int main(int argc, char* argv[]) {
                // Optimized loop
                char s = argv[1][0];

                printf("s = %c\n", s);

                return 0;
}


Is there an optimization that can do this?
And if not, maybe someone knows what hinders the optimizer?!


Thanks,
Peter
________________________________
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190813/6f49546e/attachment.html>


More information about the llvm-dev mailing list