[LLVMdev] InstCombine strips the inBounds attribute in GetElementPtr ConstantExpr

Jingyue Wu jingyue at google.com
Tue Apr 22 10:37:56 PDT 2014


Sure, Chandler. I was running late yesterday, and didn't get a chance to
reduce it.

Attached is a reduced test. One more thing I found is, to trigger this
issue, the base of the GEP mustn't be a GlobalVariable; otherwise, LLVM
will go to ConstantFold.cpp:2131 and generate an inbounds GEP ConstantExpr.

2127   // If all indices are known integers and normalized, we can do a
simple
2128   // check for the "inbounds" property.

2129   if (!Unknown && !inBounds &&

2130       isa<GlobalVariable>(C) && isInBoundsIndices(Idxs))

2131     return ConstantExpr::getInBoundsGetElementPtr(C, Idxs);


My attached test is reduced from a CUDA program that declares the global
array as __shared__. Therefore, the base of the GEP is an addrspacecast
from the global array.

One possible fix is to pass IsInBounds to ConstantFoldInstOperands and
CastGEPIndices, so that CastGEPIndices can inherit this attribute. Are
there better ways?

Let me know if you need more information.

Jingyue


On Mon, Apr 21, 2014 at 8:04 PM, Chandler Carruth <chandlerc at google.com>wrote:

>
> On Mon, Apr 21, 2014 at 7:59 PM, Jingyue Wu <jingyue at google.com> wrote:
>
>> I can't upload my program due to confidentiality, but the problem is
>> obvious.
>
>
> A reduced test case would still help, and should go into any fix to ensure
> we don't regress here...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140422/57574e0e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inbounds.ll
Type: application/octet-stream
Size: 367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140422/57574e0e/attachment.obj>


More information about the llvm-dev mailing list