Budukh, Tejas via llvm-dev
2015-Nov-06 17:43 UTC
[llvm-dev] [PATCH] patch for missed constantFold optimization in InstCombine
Hi All, llvm::ConstantFoldCompareInstOperands misses an optimization when it tries to constantFold a compare instruction containing addrspacecast instead of combination of ptrtoint and inttoptr. Adding the patched code snippet in the code would enable the pass to handle addrspacecast and constantFold the missing cases. Attached is the .ll file for the reproducer. Let me know if there are any suggestions/comments or I can commit the patch. Patched code : Index: ConstantFolding.cpp ==================================================================diff --git a/llvm/trunk/lib/Analysis/ConstantFolding.cpp b/llvm/trunk/lib/Analysis/ConstantFolding.cpp --- a/llvm/trunk/lib/Analysis/ConstantFolding.cpp (revision 252222) +++ b/llvm/trunk/lib/Analysis/ConstantFolding.cpp (working copy) @@ -1137,6 +1137,12 @@ return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI); } } + + if (CE0->getOpcode() == Instruction::AddrSpaceCast) { + Constant *C = CE0->getOperand(0); + Constant *Null = Constant::getNullValue(C->getType()); + return ConstantFoldCompareInstOperands(Predicate, C, Null, TD, TLI); + } } if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(Ops1)) { Thanks, Tejas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151106/7093b1a8/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: instCombineAddrspaceCast.ll Type: application/octet-stream Size: 1110 bytes Desc: instCombineAddrspaceCast.ll URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151106/7093b1a8/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: ConstantFolding.cpp.patch Type: application/octet-stream Size: 799 bytes Desc: ConstantFolding.cpp.patch URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151106/7093b1a8/attachment-0001.obj>