<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Thx for trying, Sanjay.<br>
<br>
Now that I try and compile x86_64, I too see addq: clang -Os lsr.c
-S -o -<br>
<br>
But when I compile clang -Os lsr.c -S -emit-llvm -o -, I see
multiplies :(<br>
<br>
I even tried clang -Os hello48.c -S -emit-llvm -loop-reduce
-loop-strength-reduce -o - for good measure. Still multiples :(<br>
<br>
I am using a variety of LLVM versions; you are presumably using the
bleeding edge. Do you also get multiplies in the IR?<br>
<br>
(I am working on a backend which is not x86_64)<br>
<br>
thousand thanks,<br>
Will<br>
<br>
<div class="moz-cite-prefix">On 04/01/16 17:31, Sanjay Patel wrote:<br>
</div>
<blockquote
cite="mid:CA+wODitLr5BPz23iCXFf-024u920tWCfoV3DD-GujsX8owEvvA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>This should be handled in:<br>
<a moz-do-not-send="true"
href="https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Scalar/LoopStrengthReduce.cpp">https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Scalar/LoopStrengthReduce.cpp</a><br>
<br>
</div>
And it seems to work for both of your examples (x86-64 target):<br>
$ ./clang -Os lsr.c -S -o - | grep addq<br>
addq (%rsi), %rax<br>
addq $96, %rsi ; 12 * 8 bytes<br>
addq $44, %rbx ; 11 * 4 bytes<br>
<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Jan 4, 2016 at 3:27 AM, Will
via llvm-dev <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Here is a
simple loop:<br>
<br>
long foo(int len, long* s) {<br>
long sum = 0;<br>
for (int i=0; i<len; i++)<br>
sum += s[i*12];<br>
return sum;<br>
}<br>
<br>
There is a multiplication in each loop iteration. Can this
be turned<br>
into addition, and is there already a pass that does?<br>
<br>
(<a moz-do-not-send="true"
href="https://en.wikipedia.org/wiki/Strength_reduction"
rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Strength_reduction</a>
uses this very<br>
situation as an example in the opening paragraph:<br>
<br>
"In software engineering, strength reduction is a compiler
optimization<br>
where expensive operations are replaced with equivalent but
less<br>
expensive operations. The classic example of strength
reduction converts<br>
"strong" multiplications inside a loop into "weaker"
additions –<br>
something that frequently occurs in array addressing." :) )<br>
<br>
And here is another loop:<br>
<br>
extern void foo(int);<br>
<br>
typedef struct {int i; int a[10];} S;<br>
<br>
void bar(S* A) {<br>
for(int i = 50; i < 400;i++)<br>
foo(A[i].i);<br>
}<br>
<br>
In this case, there is a multiplication in each loop
iteration 'hidden'<br>
in the GEP. Can this be turned into addition too?<br>
<br>
I was hoping the loop-reduce pass would do this kind of
thing; should it?<br>
<br>
Thx<br>
Will<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a moz-do-not-send="true"
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>