[llvm] [PatternMatch] Add a matching helper `m_ElementWiseBitCast`. NFC. (PR #80764)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 00:18:37 PST 2024
================
@@ -182,9 +182,15 @@ Instruction *InstCombinerImpl::commonCastTransforms(CastInst &CI) {
if (!Cmp || Cmp->getOperand(0)->getType() != Sel->getType() ||
(CI.getOpcode() == Instruction::Trunc &&
shouldChangeType(CI.getSrcTy(), CI.getType()))) {
- if (Instruction *NV = FoldOpIntoSelect(CI, Sel)) {
- replaceAllDbgUsesWith(*Sel, *NV, CI, DT);
- return NV;
+
+ // If it's a bitcast involving vectors, make sure it has the same number
+ // of elements on both sides.
+ if (CI.getOpcode() != Instruction::BitCast ||
+ match(&CI, m_ElementWiseBitCast(m_Value()))) {
+ if (Instruction *NV = FoldOpIntoSelect(CI, Sel)) {
+ replaceAllDbgUsesWith(*Sel, *NV, CI, DT);
+ return NV;
----------------
dtcxzyw wrote:
I removed the check in `InstructionCombing.cpp`:
```
// If it's a bitcast involving vectors, make sure it has the same number of
// elements on both sides.
if (auto *BC = dyn_cast<BitCastInst>(&Op)) {
VectorType *DestTy = dyn_cast<VectorType>(BC->getDestTy());
VectorType *SrcTy = dyn_cast<VectorType>(BC->getSrcTy());
// Verify that either both or neither are vectors.
if ((SrcTy == nullptr) != (DestTy == nullptr))
return nullptr;
// If vectors, verify that they have the same number of elements.
if (SrcTy && SrcTy->getElementCount() != DestTy->getElementCount())
return nullptr;
}
```
https://github.com/llvm/llvm-project/pull/80764
More information about the llvm-commits
mailing list