From 95a440b936c26b97eb47d691df551d21ce8c13d3 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 1 Oct 2020 14:36:42 +0100 Subject: [PATCH] [IR] PatternMatch - add m_FShl/m_FShr funnel shift intrinsic matchers. NFCI. --- llvm/include/llvm/IR/PatternMatch.h | 12 ++++++++++++ llvm/lib/Analysis/InstructionSimplify.cpp | 15 +++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 78a311d..000a3af 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 7645cc9..c139661 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 && -- 2.7.4