[llvm] [VectorCombine] Fold bitcast(bitreverse.v8i8(bitcast(IntTy))) into bswap+bitreverse (PR #209037)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 02:35:26 PDT 2026


================
@@ -6118,6 +6118,45 @@ bool VectorCombine::foldBitcastOfVPLoad(Instruction &I) {
 ///   bitreverse(bswap(x)) --> bitcast(bitreverse(bitcast(x)))
 bool VectorCombine::foldBitOrderReverseAndSwap(Instruction &I) {
   Value *X;
+
+  if (match(&I, m_BitCast(m_Intrinsic<Intrinsic::bitreverse>(
+                    m_BitCast(m_Value(X)))))) {
+    Type *Ty = X->getType();
+    Type *VecTy = cast<BitCastInst>(&I)->getOperand(0)->getType();
+    if (Ty->isIntegerTy() && Ty == I.getType() && isa<FixedVectorType>(VecTy) &&
+        cast<FixedVectorType>(VecTy)->getElementType()->isIntegerTy(8) &&
+        Ty->getIntegerBitWidth() % 16 == 0) {
+      auto *InnerCall = cast<Instruction>(cast<BitCastInst>(&I)->getOperand(0));
+      // OldCost = bitcast to vec + bitreverse.v8i8 + bitcast to int
----------------
RKSimon wrote:

not sure if this comment adds much - a short overview comment at the top of the if() would be better

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


More information about the llvm-commits mailing list