[llvm] r324631 - [InstCombine] Add m_Negative pattern matching
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 10:36:01 PST 2018
Author: rksimon
Date: Thu Feb 8 10:36:01 2018
New Revision: 324631
URL: http://llvm.org/viewvc/llvm-project?rev=324631&view=rev
Log:
[InstCombine] Add m_Negative pattern matching
Allows us to add non-uniform constant vector support for "X urem C -> X < C ? X : X - C, where C >= signbit."
Modified:
llvm/trunk/include/llvm/IR/PatternMatch.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/vector-urem.ll
Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=324631&r1=324630&r2=324631&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Thu Feb 8 10:36:01 2018
@@ -339,6 +339,14 @@ template <typename Predicate> struct api
}
};
+struct is_negative {
+ bool isValue(const APInt &C) { return C.isNegative(); }
+};
+
+/// \brief Match an integer or vector of negative values.
+inline cst_pred_ty<is_negative> m_Negative() { return cst_pred_ty<is_negative>(); }
+inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
+
struct is_power2 {
bool isValue(const APInt &C) { return C.isPowerOf2(); }
};
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=324631&r1=324630&r2=324631&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Thu Feb 8 10:36:01 2018
@@ -1604,8 +1604,7 @@ Instruction *InstCombiner::visitURem(Bin
}
// X urem C -> X < C ? X : X - C, where C >= signbit.
- const APInt *DivisorC;
- if (match(Op1, m_APInt(DivisorC)) && DivisorC->isNegative()) {
+ if (match(Op1, m_Negative())) {
Value *Cmp = Builder.CreateICmpULT(Op0, Op1);
Value *Sub = Builder.CreateSub(Op0, Op1);
return SelectInst::Create(Cmp, Op0, Sub);
Modified: llvm/trunk/test/Transforms/InstCombine/vector-urem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vector-urem.ll?rev=324631&r1=324630&r2=324631&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vector-urem.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vector-urem.ll Thu Feb 8 10:36:01 2018
@@ -59,8 +59,10 @@ define <4 x i32> @test_v4i32_negconstspl
define <4 x i32> @test_v4i32_negconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_negconst(
-; CHECK-NEXT: [[TMP1:%.*]] = urem <4 x i32> [[A0:%.*]], <i32 -3, i32 -5, i32 -7, i32 -9>
-; CHECK-NEXT: ret <4 x i32> [[TMP1]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <4 x i32> [[A0:%.*]], <i32 -3, i32 -5, i32 -7, i32 -9>
+; CHECK-NEXT: [[TMP2:%.*]] = add <4 x i32> [[A0]], <i32 3, i32 5, i32 7, i32 9>
+; CHECK-NEXT: [[TMP3:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> [[A0]], <4 x i32> [[TMP2]]
+; CHECK-NEXT: ret <4 x i32> [[TMP3]]
;
%1 = urem <4 x i32> %a0, <i32 -3, i32 -5, i32 -7, i32 -9>
ret <4 x i32> %1
More information about the llvm-commits
mailing list