|
37 | 37 | #include "llvm/CodeGen/MachineFunction.h"
|
38 | 38 | #include "llvm/CodeGen/MachineMemOperand.h"
|
39 | 39 | #include "llvm/CodeGen/RuntimeLibcalls.h"
|
| 40 | +#include "llvm/CodeGen/SDPatternMatch.h" |
40 | 41 | #include "llvm/CodeGen/SelectionDAGAddressAnalysis.h"
|
41 | 42 | #include "llvm/CodeGen/SelectionDAGNodes.h"
|
42 | 43 | #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
|
|
81 | 82 | #include <vector>
|
82 | 83 |
|
83 | 84 | using namespace llvm;
|
| 85 | +using namespace llvm::SDPatternMatch; |
84 | 86 |
|
85 | 87 | /// makeVTList - Return an instance of the SDVTList struct initialized with the
|
86 | 88 | /// specified members.
|
@@ -4290,21 +4292,15 @@ bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth) const {
|
4290 | 4292 | return isKnownToBeAPowerOfTwo(Val.getOperand(2), Depth + 1) &&
|
4291 | 4293 | isKnownToBeAPowerOfTwo(Val.getOperand(1), Depth + 1);
|
4292 | 4294 |
|
4293 |
| - if (Val.getOpcode() == ISD::AND) { |
4294 |
| - // Looking for `x & -x` pattern: |
4295 |
| - // If x == 0: |
4296 |
| - // x & -x -> 0 |
4297 |
| - // If x != 0: |
4298 |
| - // x & -x -> non-zero pow2 |
4299 |
| - // so if we find the pattern return whether we know `x` is non-zero. |
4300 |
| - for (unsigned OpIdx = 0; OpIdx < 2; ++OpIdx) { |
4301 |
| - SDValue NegOp = Val.getOperand(OpIdx); |
4302 |
| - if (NegOp.getOpcode() == ISD::SUB && |
4303 |
| - NegOp.getOperand(1) == Val.getOperand(1 - OpIdx) && |
4304 |
| - isNullOrNullSplat(NegOp.getOperand(0))) |
4305 |
| - return isKnownNeverZero(Val.getOperand(1 - OpIdx), Depth); |
4306 |
| - } |
4307 |
| - } |
| 4295 | + // Looking for `x & -x` pattern: |
| 4296 | + // If x == 0: |
| 4297 | + // x & -x -> 0 |
| 4298 | + // If x != 0: |
| 4299 | + // x & -x -> non-zero pow2 |
| 4300 | + // so if we find the pattern return whether we know `x` is non-zero. |
| 4301 | + SDValue X; |
| 4302 | + if (sd_match(Val, m_And(m_Value(X), m_Sub(m_Zero(), m_Deferred(X))))) |
| 4303 | + return isKnownNeverZero(X, Depth); |
4308 | 4304 |
|
4309 | 4305 | if (Val.getOpcode() == ISD::ZERO_EXTEND)
|
4310 | 4306 | return isKnownToBeAPowerOfTwo(Val.getOperand(0), Depth + 1);
|
|
0 commit comments