Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,7 @@ template <typename Opnd_t> struct Signum_match {
return false;

unsigned ShiftWidth = TypeSize - 1;
Value *OpL = nullptr, *OpR = nullptr;
Value *Op;

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

auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
auto Signum = m_Or(LHS, RHS);
auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
auto Signum = m_c_Or(LHS, RHS);

return Signum.match(V) && OpL == OpR && Val.match(OpL);
return Signum.match(V) && Val.match(Op);
}
};

Expand Down
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/compare-signs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ define i1 @test4a(i32 %a) {
ret i1 %c
}

define i1 @test4a_commuted(i32 %a) {
; CHECK-LABEL: @test4a_commuted(
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[SIGNUM:%.*]], 1
; CHECK-NEXT: ret i1 [[C]]
;
%l = ashr i32 %a, 31
%na = sub i32 0, %a
%r = lshr i32 %na, 31
%signum = or i32 %r, %l
%c = icmp slt i32 %signum, 1
ret i1 %c
}

define <2 x i1> @test4a_vec(<2 x i32> %a) {
; CHECK-LABEL: @test4a_vec(
; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[A:%.*]], splat (i32 1)
Expand Down
Loading