[PATCH] D124590: [InstCombine] add casts from splat-a-bit pattern if necessary

Chenbing.Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 20:10:37 PDT 2022


Chenbing.Zheng added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp:1605-1606
+                                        AshrAmtC);
+    Instruction *SrcInst = dyn_cast<Instruction>(Src);
+    if (SrcInst && SrcInst->getOperand(0)->hasOneUse()) {
+      Value *Ashr = Builder.CreateAShr(Builder.CreateShl(X, ShlAmtC), AshrAmtC);
----------------
spatel wrote:
> There's a potential subtle difference with constant expressions, but you could reduce this to:
>     if (cast<BinaryOperator>(Src)->getOperand(0)->hasOneUse()) {
> 
> The m_Ashr guarantees that we matched a binary operator, so it's ok to plain "cast" it to that type. You could also capture the trunc in the first match with something like this:
> 
>   Instruction *Trunc;
>   if (match(Src, m_OneUse(m_AShr(
>                      m_CombineAnd(m_Trunc(m_Value(X)), m_Instruction(Trunc)),
>                      m_SpecificInt(SrcBitSize - 1))))) {
> 
> Then the use check is the straightforward:
>     if (Trunc->hasOneUse()) {
> 
Done and thank you for your detailed explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124590



More information about the llvm-commits mailing list