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>
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.
Thanks a lot for your help.
Indeed if I compile with -OZ the loop gets replaced with something like this:
if ( *v3 < 0 )
v4 = 0;
Is there a reason why it does not get applied with O3 ?
I mean this a huge improvement to the loop.
-----Original Message-----
From: Doerfert, Johannes [mailto:jdoerfert at anl.gov]
Sent: Dienstag, 13. August 2019 19:13
To: llvm-dev at lists.llvm.org; Garba Peter <peter.garba at gemalto.com>
Subject: Re: Loop optimization
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.
________________________________
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.