[llvm-dev] [PATCH] patch for missed constantFold optimization in InstCombine

Budukh, Tejas via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 10 13:58:55 PST 2015


Hi,
Any reviewers for this patch ? Any suggestions ?
Opt tool's output for this ll before and after the patch is also attached.

Thanks,
Tejas

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Budukh, Tejas via llvm-dev
Sent: Friday, November 06, 2015 9:43 AM
To: llvm-dev at lists.llvm.org
Subject: [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/20151110/9de67270/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/20151110/9de67270/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/20151110/9de67270/attachment-0001.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: new_Output.txt
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151110/9de67270/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: old_Output.txt
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151110/9de67270/attachment-0001.txt>


More information about the llvm-dev mailing list