[PATCH] D76983: [InstCombine] Transform extractelement-trunc -> bitcast-extractelement

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 07:32:12 PDT 2020


spatel added a reviewer: lebedev.ri.
spatel added a comment.

In D76983#1947820 <https://reviews.llvm.org/D76983#1947820>, @dsprenkels wrote:

> It was a bit unclear to me how involved the tests should be for this patch. At this time, I kept them pretty minimal, but I could add more if that's desired.


I didn't look at the logic closely, but seems to be on the right track from the tests (feel free to include Alive2 links in the review if you tested any/all of these).
I see at least 2 variations where we need more code logic (and more tests):

  ; In IR, crazy types are allowed.
  define i13 @shrinkExtractElt_i67_to_i13_2(<3 x i67> %x) {
    %e = extractelement <3 x i67> %x, i459 2
    %t = trunc i67 %e to i13
    ret i13 %t
  }
  
  ; We generally don't want to canonicalize to a form that increases the instruction count.
  declare void @use(i64)
  define i16 @shrinkExtractElt_i64_to_i16_2_extra_use(<3 x i64> %x) {
    %e = extractelement <3 x i64> %x, i64 2
    call void @use(i64 %e)
    %t = trunc i64 %e to i16
    ret i16 %t
  }

I didn't run those through 'opt', so check for typos.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp:854
+  ///   extractelement <8 x i32> (bitcast <4 x i64> %X to <8 x i32>), i32 0
+  if (auto *ExtElt = dyn_cast<ExtractElementInst>(CI.getOperand(0))) {
+    Value *VecOp = ExtElt->getVectorOperand();
----------------
m_ExtractElement() for matching/capturing the operands ?


================
Comment at: llvm/test/Transforms/InstCombine/pr45314_be.ll:3
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
----------------
Only need the first "E" here (and that makes it clear that the transform depends on endian and not something else in that string).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76983





More information about the llvm-commits mailing list