[PATCH] D137934: [InstCombine] Fold extractelt with select of constants

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 06:22:12 PST 2022


foad added a comment.

> extractelt (select %cond, <vec1>, <vec2>), %c1, %c2 ->
> select %cond, <vec1>[c1], <vec2>[c2]

What are %c1 and %c2? Surely these is only one index?

Also your description does not make it clear that you are only doing this for constant vectors. For general vectors it could be: extractelt (select %cond, <vec1>, <vec2>), %c -> select %cond, (extractelt <vec1>, %c), (extractelt <vec2>, %c)



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:396
+                                                 Value *Vec, ConstantInt *Idx) {
+  if (!EI.hasOneUse())
+    return nullptr;
----------------
Why do you need to check this? Generally it is OK when the top-level thing has multiple uses.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:403
+    auto *FalseVal = dyn_cast<ConstantVector>(Select->getFalseValue());
+    if (TrueVal && FalseVal) {
+      const uint64_t IndexVal = Idx->getValue().getZExtValue();
----------------
In most case you should use an early "return nullptr" to reduce indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137934



More information about the llvm-commits mailing list