diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-02-07 21:02:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 21:02:13 +0800 |
commit | f37d81f8a3e1475f30bec63bfc0b703fc9509d7c (patch) | |
tree | 21595fc7758aa40bd82c92e72c017cf22386c743 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | d109f94f29e2bc2fc31c8870b1e41759f524fe77 (diff) | |
download | llvm-f37d81f8a3e1475f30bec63bfc0b703fc9509d7c.zip llvm-f37d81f8a3e1475f30bec63bfc0b703fc9509d7c.tar.gz llvm-f37d81f8a3e1475f30bec63bfc0b703fc9509d7c.tar.bz2 |
[PatternMatch] Add a matching helper `m_ElementWiseBitCast`. NFC. (#80764)
This patch introduces a matching helper `m_ElementWiseBitCast`, which is
used for matching element-wise int <-> fp casts.
The motivation of this patch is to avoid duplicating checks in
https://github.com/llvm/llvm-project/pull/80740 and
https://github.com/llvm/llvm-project/pull/80414.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 58f0763..ed47de28 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -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; + } } } } |