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

David Majnemer via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 10 14:29:14 PST 2015


Please send patches to llvm-commits as per our policy:
http://llvm.org/docs/DeveloperPolicy.html

Also, your test-case needs to use FileCheck.

On Tue, Nov 10, 2015 at 1:58 PM, Budukh, Tejas via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151110/39570a82/attachment.html>


More information about the llvm-dev mailing list