On 11/17/2017 03:45 PM, Qing Zhao wrote: >>> do you think using this routine is good? or do you have other >>> suggestions (since I am still not very familiar with the internals of >>> GCC, might not find the best available one now…) >> The range information attached to an SSA_NAME is global data. ie, it >> must hold at all locations where the object in question might be >> referenced. This implies that it will sometimes (often?) be less >> precise than you might like. > > do you mean the “value_range” attached to SSA_NAME? > > For my purpose, I’d like to get the maximum length of char array s[100] is > 100, which is larger than the size of constant string “abc”, then > I can safely apply the transformation to memcmp. > > can “value_range” info serve this purpose? No it can't. Sorry for leading you the wrong direction. What you're looking for is the object size interfaces.
See tree-object-size.[ch] That's a pass that tries to compute the sizes of various objects referenced by the IL. Note that the object size is different than say the length of a string stored in an object for which you'll probably be looking at tree-ssa-strlen's interfaces. Ranges are more for integer objects. ie, i has the value [0,25] or ~[0,0]. > >> >> I am currently working towards an embeddable context sensitive range >> analyzer that in theory could be used within tree-ssa-strlen pass to >> give more precise range information. I'm hoping to wrap that work up in >> the next day or so so that folks can use it in gcc-8. > > such context sensitive range info should be useful when we relax the constant > “N” to be an expression whose Min value is larger than the length > of constant string, with it, we can catch more opportunities. > let me know when this info is available. Hoping to have the basics into the trunk within the next few days as reviews flow in. jeff