diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 78a311de065750..000a3af4cc2cf1 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -2015,6 +2015,18 @@ inline typename m_Intrinsic_Ty::Ty m_FMax(const Opnd0 &Op0, return m_Intrinsic(Op0, Op1); } +template +inline typename m_Intrinsic_Ty::Ty +m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) { + return m_Intrinsic(Op0, Op1, Op2); +} + +template +inline typename m_Intrinsic_Ty::Ty +m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) { + return m_Intrinsic(Op0, Op1, Op2); +} + //===----------------------------------------------------------------------===// // Matchers for two-operands operators with the operators in either order // diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 7645cc93545ccc..c13966169eeba8 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3963,10 +3963,8 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, // Test for a bogus zero-shift-guard-op around funnel-shift or rotate. Value *ShAmt; - auto isFsh = m_CombineOr(m_Intrinsic(m_Value(X), m_Value(), - m_Value(ShAmt)), - m_Intrinsic(m_Value(), m_Value(X), - m_Value(ShAmt))); + auto isFsh = m_CombineOr(m_FShl(m_Value(X), m_Value(), m_Value(ShAmt)), + m_FShr(m_Value(), m_Value(X), m_Value(ShAmt))); // (ShAmt == 0) ? fshl(X, *, ShAmt) : X --> X // (ShAmt == 0) ? fshr(*, X, ShAmt) : X --> X if (match(TrueVal, isFsh) && FalseVal == X && CmpLHS == ShAmt) @@ -3977,12 +3975,9 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, // intrinsics do not have that problem. // We do not allow this transform for the general funnel shift case because // that would not preserve the poison safety of the original code. - auto isRotate = m_CombineOr(m_Intrinsic(m_Value(X), - m_Deferred(X), - m_Value(ShAmt)), - m_Intrinsic(m_Value(X), - m_Deferred(X), - m_Value(ShAmt))); + auto isRotate = + m_CombineOr(m_FShl(m_Value(X), m_Deferred(X), m_Value(ShAmt)), + m_FShr(m_Value(X), m_Deferred(X), m_Value(ShAmt))); // (ShAmt == 0) ? X : fshl(X, X, ShAmt) --> fshl(X, X, ShAmt) // (ShAmt == 0) ? X : fshr(X, X, ShAmt) --> fshr(X, X, ShAmt) if (match(FalseVal, isRotate) && TrueVal == X && CmpLHS == ShAmt &&