[ConstantFold] allow folding icmp of null and constexpr
authorSanjay Patel <spatel@rotateright.com>
Mon, 8 Mar 2021 13:52:12 +0000 (08:52 -0500)
committerSanjay Patel <spatel@rotateright.com>
Mon, 8 Mar 2021 13:53:59 +0000 (08:53 -0500)
commitf75b5305f4def4973027a9b96fb3f1e50ce056e3
tree9950eeed6bc52c548c7d7de567440bbfbc66b89a
parenta093942c287501484481384dd03686ffaa5fc98e
[ConstantFold] allow folding icmp of null and constexpr

I noticed that we were not folding expressions like this:
icmp ult (constexpr), null
in https://llvm.org/PR49355, so we end up with extremely large
icmp instructions as the constant expressions pile up on each other.

There is no potential to mis-fold an unsigned boundary condition
with a zero/null, so this is just falling through a crack in the
pattern matching.

The more general case of comparisons of non-zero constants and
constexpr are more tricky and may require the datalayout to know
how to cast to different types, etc. Negative tests verify that
we are only changing a subset of potential patterns.

Differential Revision: https://reviews.llvm.org/D98150
llvm/lib/IR/ConstantFold.cpp
llvm/test/CodeGen/PowerPC/pr46923.ll
llvm/test/Transforms/InstCombine/vector_gep1-inseltpoison.ll
llvm/test/Transforms/InstCombine/vector_gep1.ll
llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
llvm/test/Transforms/JumpThreading/thread-two-bbs.ll