Jingyue Wu
2014-Apr-22 02:59 UTC
[LLVMdev] InstCombine strips the inBounds attribute in GetElementPtr ConstantExpr
I can't upload my program due to confidentiality, but the problem is obvious. At lib/Analysis/ConstantFolding.cpp:646 Constant *C = ConstantExpr::getGetElementPtr(Ops[0], NewIdxs); if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI)) C = Folded; } The generated ConstantExpr C doesn't inherit the inBounds attribute of the original GEP. FYI, the callstack is #0 CastGEPIndices (Ops=..., ResultTy=0x2fb2850, TD=0x2fc8830, TLI=0x2feb390) at ConstantFolding.cpp:623 #1 0x0000000001892dd1 in llvm::ConstantFoldInstOperands (Opcode=29, DestTy=0x2fb2850, Ops=..., TD=0x2fc8830, TLI=0x2feb390) at ConstantFolding.cpp:1040 #2 0x0000000001892647 in ConstantFoldConstantExpressionImpl (CE=0x2fcb0f8, TD=0x2fc8830, TLI=0x2feb390, FoldedOps=...) at ConstantFolding.cpp:931 #3 0x00000000018926d5 in llvm::ConstantFoldConstantExpression (CE=0x2fcb0f8, TD=0x2fc8830, TLI=0x2feb390) at ConstantFolding.cpp:941 #4 0x0000000001892226 in llvm::ConstantFoldInstruction (I=0x2fcb208, TD=0x2fc8830, TLI=0x2feb390) at ConstantFolding.cpp:883 #5 0x000000000171284e in AddReachableCodeToWorklist (BB=0x2fca970, Visited=..., IC=..., DL=0x2fc8830, TLI=0x2feb390) at InstructionCombining.cpp:2283 #6 0x0000000001712e91 in llvm::InstCombiner::DoOneIteration (this=0x2ff3be0, F=..., Iteration=0) at InstructionCombining.cpp:2369 #7 0x0000000001713bf2 in llvm::InstCombiner::runOnFunction (this=0x2ff3be0, F=...) at InstructionCombining.cpp:2568 Jingyue -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140421/faad8378/attachment.html>
Chandler Carruth
2014-Apr-22 03:04 UTC
[LLVMdev] InstCombine strips the inBounds attribute in GetElementPtr ConstantExpr
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/20140421/f8693333/attachment.html>
Jingyue Wu
2014-Apr-22 17:37 UTC
[LLVMdev] InstCombine strips the inBounds attribute in GetElementPtr ConstantExpr
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>