[llvm-dev] Loop optimization

Doerfert, Johannes via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 13 10:12:39 PDT 2019


Without testing it I'd say loop idiom recognition (Transforms/Scalar/LoopIdiomRecognize.h) is the one that should kick in and optimize this.

________________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Garba Peter via llvm-dev <llvm-dev at lists.llvm.org>
Sent: Tuesday, August 13, 2019 11:54
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Loop optimization

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.


More information about the llvm-dev mailing list