[llvm] [VectorCombine] foldBitcastShuffle - peek through any residual bitcasts before creating a new bitcast on top (PR #86119)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 07:02:01 PDT 2024


================
@@ -135,6 +135,18 @@ class VectorCombine {
 };
 } // namespace
 
+/// Return the source operand of a potentially bitcasted value while
+/// optionally checking if it has one use. If there is no bitcast or the one
+/// use check is not met, return the input value itself.
+static Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
+  if (auto *BitCast = dyn_cast<BitCastInst>(V))
+    if (!OneUseOnly || BitCast->hasOneUse())
+      return BitCast->getOperand(0);
----------------
phoebewang wrote:

Maybe

```suggestion
  while (auto *BitCast = dyn_cast<BitCastInst>(V))
    if (!OneUseOnly || BitCast->hasOneUse())
      V = BitCast->getOperand(0);
```

https://github.com/llvm/llvm-project/pull/86119


More information about the llvm-commits mailing list