|
27 | 27 | #include "llvm/Analysis/BlockFrequencyInfo.h"
|
28 | 28 | #include "llvm/Analysis/ProfileSummaryInfo.h"
|
29 | 29 | #include "llvm/Analysis/VectorUtils.h"
|
| 30 | +#include "llvm/CodeGen/ISDOpcodes.h" |
30 | 31 | #include "llvm/CodeGen/IntrinsicLowering.h"
|
31 | 32 | #include "llvm/CodeGen/LivePhysRegs.h"
|
32 | 33 | #include "llvm/CodeGen/MachineFrameInfo.h"
|
@@ -35386,8 +35387,26 @@ bool X86TargetLowering::isNarrowingProfitable(SDNode *N, EVT SrcVT,
|
35386 | 35387 | bool X86TargetLowering::shouldFoldSelectWithIdentityConstant(
|
35387 | 35388 | unsigned BinOpcode, EVT VT, unsigned SelectOpcode, SDValue X,
|
35388 | 35389 | SDValue NonIdConstNode) const {
|
35389 |
| - if (SelectOpcode != ISD::VSELECT) |
| 35390 | + if (SelectOpcode == ISD::SELECT) { |
| 35391 | + if (VT.isVector()) |
| 35392 | + return false; |
| 35393 | + if (!Subtarget.hasBMI() || (VT != MVT::i32 && VT != MVT::i64)) |
| 35394 | + return false; |
| 35395 | + using namespace llvm::SDPatternMatch; |
| 35396 | + // BLSI |
| 35397 | + if (BinOpcode == ISD::AND && sd_match(NonIdConstNode, m_Neg(m_Specific(X)))) |
| 35398 | + return true; |
| 35399 | + // BLSR |
| 35400 | + if (BinOpcode == ISD::AND && |
| 35401 | + sd_match(NonIdConstNode, m_Add(m_Specific(X), m_AllOnes()))) |
| 35402 | + return true; |
| 35403 | + // BLSMSK |
| 35404 | + if (BinOpcode == ISD::XOR && |
| 35405 | + sd_match(NonIdConstNode, m_Add(m_Specific(X), m_AllOnes()))) |
| 35406 | + return true; |
| 35407 | + |
35390 | 35408 | return false;
|
| 35409 | + } |
35391 | 35410 | // TODO: This is too general. There are cases where pre-AVX512 codegen would
|
35392 | 35411 | // benefit. The transform may also be profitable for scalar code.
|
35393 | 35412 | if (!Subtarget.hasAVX512())
|
|
0 commit comments