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

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 08:43:37 PDT 2022


spatel 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);
----------------
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()) {



================
Comment at: llvm/test/Transforms/InstCombine/sext.ll:414
+
+define i64 @smear_set_bit_different_dest_type_wider_dst(i32 %x) {
+; CHECK-LABEL: @smear_set_bit_different_dest_type_wider_dst(
----------------
Please pre-commit the baseline tests and update here, so we just show the diffs.


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