Skip to content

Commit f578320

Browse files
committed
[PatternMatch] Match commuted patterns in Signum_match
1 parent aa5e48a commit f578320

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ template <typename Opnd_t> struct Signum_match {
28702870
return false;
28712871

28722872
unsigned ShiftWidth = TypeSize - 1;
2873-
Value *OpL = nullptr, *OpR = nullptr;
2873+
Value *Op;
28742874

28752875
// This is the representation of signum we match:
28762876
//
@@ -2882,11 +2882,11 @@ template <typename Opnd_t> struct Signum_match {
28822882
//
28832883
// for i1 values.
28842884

2885-
auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
2886-
auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
2887-
auto Signum = m_Or(LHS, RHS);
2885+
auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
2886+
auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
2887+
auto Signum = m_c_Or(LHS, RHS);
28882888

2889-
return Signum.match(V) && OpL == OpR && Val.match(OpL);
2889+
return Signum.match(V) && Val.match(Op);
28902890
}
28912891
};
28922892

llvm/test/Transforms/InstCombine/compare-signs.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ define i1 @test4a(i32 %a) {
154154

155155
define i1 @test4a_commuted(i32 %a) {
156156
; CHECK-LABEL: @test4a_commuted(
157-
; CHECK-NEXT: [[L:%.*]] = ashr i32 [[A:%.*]], 31
158-
; CHECK-NEXT: [[NA:%.*]] = sub i32 0, [[A]]
159-
; CHECK-NEXT: [[R:%.*]] = lshr i32 [[NA]], 31
160-
; CHECK-NEXT: [[SIGNUM:%.*]] = or i32 [[R]], [[L]]
161-
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[SIGNUM]], 1
157+
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[SIGNUM:%.*]], 1
162158
; CHECK-NEXT: ret i1 [[C]]
163159
;
164160
%l = ashr i32 %a, 31

0 commit comments

Comments
 (0)