LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1154 - LICM missing hoist of calls due to missing loop rotation
Summary: LICM missing hoist of calls due to missing loop rotation
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Loop Optimizer (show other bugs)
Version: trunk
Hardware: All All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords: code-quality
Depends on:
Blocks:
 
Reported: 2007-01-31 22:14 PST by Chris Lattner
Modified: 2010-02-22 12:51 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-01-31 22:14:00 PST
In this example code:

#include <stdlib.h>
#include <string.h>
#define TESTSTRING2 "Dot. date. datum. 123. Some more doubtful demonstration dummy data."
int stringSearch_Clib (long count) {
int i, c = 0;long j;char * p;
char b[sizeof(TESTSTRING2)];

strcpy (b, TESTSTRING2);
for (j=0; j < count; j++) {
for (c=i=0; i < 250; i++) {
if (NULL != (p = strstr (b, "ummy"))) c += (int) (p - b);
if (NULL != (p = strstr (b, " data"))) c += (int) (p - b);
c += (int) strcspn (b, "by");
}
}
return c;
}

The calls to strstr and strcspn are loop invariant and should be hoisted.  They aren't though, because 
the inner loop isn't getting rotated.  This can easily be seen with:

$ llvm-gcc t.c -emit-llvm -O3 -o - -S | llvm-as | opt -print-cfg

and then viewing cfg.stringSearch_Clib.dot.

-Chris
Comment 1 Chris Lattner 2007-01-31 22:14:54 PST
This should be straight-forward to implement when the LoopPassMgr stuff comes up.
Comment 2 Reid Spencer 2007-04-08 21:15:56 PDT
We now have a LoopPassManager and a LoopRotation pass. Is this now fixed or is
fixing it now possible?
Comment 3 Chris Lattner 2007-04-08 21:59:35 PDT
Loop rotation isn't on by default yet.  Devang, please use this as a testcase when it goes in.

-Chris
Comment 4 Devang Patel 2007-04-09 10:05:47 PDT
ok
Comment 5 Devang Patel 2007-04-10 10:42:17 PDT
This is fixed. 

How do I write a test case ?
Comment 6 Reid Spencer 2007-04-10 10:48:21 PDT
Isn't the test case in the first comment in this bug sufficient?
Comment 7 Devang Patel 2007-04-10 10:49:41 PDT
No :)

I verified CFG. My question is : How to write dejagnu test ?
Comment 8 Chris Lattner 2007-04-10 11:39:26 PDT
I'd suggest using prcontext like test/Transforms/LICM/sink_inst.ll does.  This will allow you to grep for 
one of the calls and the loop header label.  The test should invoke both loop-rotate and licm.

Thanks Devang!

-Chris
Comment 9 Devang Patel 2007-04-10 11:57:24 PDT
Thanks!