[PATCH] D71389: [ConstantFold][SVE] Fix constant folding for bitcast.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 18 16:52:55 PST 2019


huihuiz added inline comments.


================
Comment at: llvm/lib/IR/ConstantFold.cpp:580
+                m_ShuffleVector(
+                    m_InsertElement(m_Undef(), m_Constant(SplatV), m_Zero()),
+                    m_Value(), m_Zero()))) {
----------------
sdesmalen wrote:
> Because we're matching for a zero mask, explicitly matching `m_Undef` here seems unnecessarily restrictive, `m_Value()` should be sufficient.
Yes, we don't need to restrict it to m_Undef().

I think we should restrict it with m_Constant(). I would expect operands to be constant at ConstantFoldCastInstruction().
Doing this can also help avoid unnecessary cast<constant> when calling ConstantExpr to get new InsertElement or cast operands into new types.


================
Comment at: llvm/lib/IR/ConstantFold.cpp:587
+            UndefValue::get(DestTy), NewCast,
+            cast<Constant>(InsertElem->getOperand(2)));
+        return ConstantExpr::getShuffleVector(
----------------
sdesmalen wrote:
> Can we match this value directly with `m_Zero(Zero)`, rather than needing `auto InsertElem` and `InsertElem->getOperand(2)` ?
Current pattern matcher doesn't support m_Zero(Zero).
I use m_CombineAnd(m_Zero(), m_Constant(Zero)) instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71389/new/

https://reviews.llvm.org/D71389





More information about the llvm-commits mailing list