Skip to content

Commit 470c5b8

Browse files
authored
[InstSimplify][InstCombine] Remove unnecessary m_c_* matchers. (#81712)
This patch removes unnecessary `m_c_*` matchers since we always canonicalize `commutive_op Cst, X` into `commutive_op X, Cst`. Compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=bfc0b7c6891896ee8e9818f22800472510093864&to=d27b058bb9acaa43d3cadbf3cd889e8f79e5c634&stat=instructions:u
1 parent 243f14d commit 470c5b8

File tree

6 files changed

+8
-38
lines changed

6 files changed

+8
-38
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static Instruction *lookThroughAnd(PHINode *Phi, Type *&RT,
7676

7777
// Matches either I & 2^x-1 or 2^x-1 & I. If we find a match, we update RT
7878
// with a new integer type of the corresponding bit width.
79-
if (match(J, m_c_And(m_Instruction(I), m_APInt(M)))) {
79+
if (match(J, m_And(m_Instruction(I), m_APInt(M)))) {
8080
int32_t Bits = (*M + 1).exactLogBase2();
8181
if (Bits > 0) {
8282
RT = IntegerType::get(Phi->getContext(), Bits);

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,8 +3246,8 @@ static bool trySimplifyICmpWithAdds(CmpInst::Predicate Pred, Value *LHS,
32463246

32473247
Value *X;
32483248
const APInt *C1, *C2;
3249-
if (!match(LHS, m_c_Add(m_Value(X), m_APInt(C1))) ||
3250-
!match(RHS, m_c_Add(m_Specific(X), m_APInt(C2))))
3249+
if (!match(LHS, m_Add(m_Value(X), m_APInt(C1))) ||
3250+
!match(RHS, m_Add(m_Specific(X), m_APInt(C2))))
32513251
return false;
32523252

32533253
return (C1->slt(*C2) && C1->isNonNegative()) ||

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ bool VPIntrinsic::canIgnoreVectorLengthParam() const {
623623
if (EC.isScalable()) {
624624
// Compare vscale patterns
625625
uint64_t VScaleFactor;
626-
if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale())))
626+
if (match(VLParam, m_Mul(m_VScale(), m_ConstantInt(VScaleFactor))))
627627
return VScaleFactor >= EC.getKnownMinValue();
628628
return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale());
629629
}

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4450,7 +4450,7 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
44504450
}
44514451

44524452
// ~(X + C) --> ~C - X
4453-
if (match(NotVal, m_c_Add(m_Value(X), m_ImmConstant(C))))
4453+
if (match(NotVal, m_Add(m_Value(X), m_ImmConstant(C))))
44544454
return BinaryOperator::CreateSub(ConstantExpr::getNot(C), X);
44554455

44564456
// ~(X - Y) --> ~X + Y

llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
258258
case Instruction::And: {
259259
Constant *ShAmt;
260260
// sub(y,and(lshr(x,C),1)) --> add(ashr(shl(x,(BW-1)-C),BW-1),y)
261-
if (match(I, m_c_And(m_OneUse(m_TruncOrSelf(
262-
m_LShr(m_Value(X), m_ImmConstant(ShAmt)))),
263-
m_One()))) {
261+
if (match(I, m_And(m_OneUse(m_TruncOrSelf(
262+
m_LShr(m_Value(X), m_ImmConstant(ShAmt)))),
263+
m_One()))) {
264264
unsigned BW = X->getType()->getScalarSizeInBits();
265265
Constant *BWMinusOne = ConstantInt::get(X->getType(), BW - 1);
266266
Value *R = Builder.CreateShl(X, Builder.CreateSub(BWMinusOne, ShAmt));

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,36 +2453,6 @@ define i1 @icmp_nsw_2(i32 %V) {
24532453
ret i1 %cmp
24542454
}
24552455

2456-
define i1 @icmp_nsw_commute(i32 %V) {
2457-
; CHECK-LABEL: @icmp_nsw_commute(
2458-
; CHECK-NEXT: ret i1 true
2459-
;
2460-
%add5 = add i32 5, %V
2461-
%add6 = add nsw i32 %V, 6
2462-
%cmp = icmp slt i32 %add5, %add6
2463-
ret i1 %cmp
2464-
}
2465-
2466-
define i1 @icmp_nsw_commute2(i32 %V) {
2467-
; CHECK-LABEL: @icmp_nsw_commute2(
2468-
; CHECK-NEXT: ret i1 true
2469-
;
2470-
%add5 = add i32 %V, 5
2471-
%add6 = add nsw i32 6, %V
2472-
%cmp = icmp slt i32 %add5, %add6
2473-
ret i1 %cmp
2474-
}
2475-
2476-
define i1 @icmp_nsw_commute3(i32 %V) {
2477-
; CHECK-LABEL: @icmp_nsw_commute3(
2478-
; CHECK-NEXT: ret i1 true
2479-
;
2480-
%add5 = add i32 5, %V
2481-
%add6 = add nsw i32 6, %V
2482-
%cmp = icmp slt i32 %add5, %add6
2483-
ret i1 %cmp
2484-
}
2485-
24862456
define i1 @icmp_nsw_22(i32 %V) {
24872457
; CHECK-LABEL: @icmp_nsw_22(
24882458
; CHECK-NEXT: ret i1 true

0 commit comments

Comments
 (0)