[llvm] 8e07124 - [InstCombine] Use constant 64-bit indices for CreateExtractElement (NFC) (#208306)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 11:49:26 PDT 2026
Author: Andreas Jonson
Date: 2026-07-09T20:49:21+02:00
New Revision: 8e0712496c891b8532157156ecacce3e5af89e26
URL: https://github.com/llvm/llvm-project/commit/8e0712496c891b8532157156ecacce3e5af89e26
DIFF: https://github.com/llvm/llvm-project/commit/8e0712496c891b8532157156ecacce3e5af89e26.diff
LOG: [InstCombine] Use constant 64-bit indices for CreateExtractElement (NFC) (#208306)
The canonical form preferred by instCombine is to use 64-bit values for
the index when it is a constant for ExtractElement.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index f630d1efbd7e7..f30a7b5e891ab 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -3416,9 +3416,7 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
// If our destination is not a vector, then make this a straight
// scalar-scalar cast.
if (!DestTy->isVectorTy()) {
- Value *Elem =
- Builder.CreateExtractElement(Src,
- Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
+ Value *Elem = Builder.CreateExtractElement(Src, uint64_t{0});
return CastInst::Create(Instruction::BitCast, Elem, DestTy);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index e6deb548819e8..42c2983034e22 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3569,10 +3569,9 @@ Instruction *InstCombinerImpl::foldICmpBitCast(ICmpInst &Cmp) {
// Fold the icmp based on the value of C
// If C is M copies of an iK sized bit pattern,
// then:
- // => %E = extractelement <N x iK> %vec, i32 Elem
+ // => %E = extractelement <N x iK> %vec, i64 Elem
// icmp <pred> iK %SplatVal, <pattern>
- Value *Elem = Builder.getInt32(Mask[0]);
- Value *Extract = Builder.CreateExtractElement(Vec, Elem);
+ Value *Extract = Builder.CreateExtractElement(Vec, Mask[0]);
Value *NewC = ConstantInt::get(EltTy, C->trunc(EltTy->getBitWidth()));
return new ICmpInst(Pred, Extract, NewC);
}
More information about the llvm-commits
mailing list