[llvm] [InstCombine] Limit canonicalization of extractelement(cast) to constant index or same basic block. (PR #166227)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 22:12:15 PST 2025


================
@@ -588,7 +588,8 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
       // Canonicalize extractelement(cast) -> cast(extractelement).
       // Bitcasts can change the number of vector elements, and they cost
       // nothing.
-      if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast)) {
+      if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast) &&
+          (EI.getParent() == CI->getParent() || isa<ConstantInt>(Index))) {
----------------
nikic wrote:

Add a comment for why this limitation exists?

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


More information about the llvm-commits mailing list