[llvm] [InstCombine] Pull shuffles out of binops with splatted ops (PR #137948)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 05:14:00 PDT 2025


================
@@ -2271,6 +2271,27 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
     }
   }
 
+  // Similar to the combine above, but handles the case for scalable vectors
+  // where both V1 and C are splats.
+  //
+  // Op(shuffle(V1, 0), (splat C)) -> shuffle(Op(V1, (splat C)), 0)
----------------
dtcxzyw wrote:

This transformation may introduce immediate UB.
Counterexample: `sdiv (splat C), shuffle(V1, 0) -> shuffle(Op((splat C), V1), 0)` is invalid if `V1` has a zero value at a non-zero index.


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


More information about the llvm-commits mailing list