Skip to content

Commit 291c1d8

Browse files
committed
[ValueTracking] Address review comment.
1 parent d5855b6 commit 291c1d8

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8522,24 +8522,21 @@ bool llvm::isKnownInversion(const Value *X, const Value *Y) {
85228522
!match(Y, m_c_ICmp(Pred2, m_Specific(A), m_Value(C))))
85238523
return false;
85248524

8525-
// If they are only differ in predicate. They must both have samesign flag or
8526-
// not.
8525+
// They must both have samesign flag or not.
8526+
if (cast<ICmpInst>(X)->hasSameSign() != cast<ICmpInst>(Y)->hasSameSign())
8527+
return false;
8528+
85278529
if (B == C)
8528-
return Pred1 == ICmpInst::getInversePredicate(Pred2) &&
8529-
(!cast<ICmpInst>(X)->hasSameSign() ||
8530-
cast<ICmpInst>(Y)->hasSameSign());
8531-
;
8530+
return Pred1 == ICmpInst::getInversePredicate(Pred2);
85328531

85338532
// Try to infer the relationship from constant ranges.
85348533
const APInt *RHSC1, *RHSC2;
85358534
if (!match(B, m_APInt(RHSC1)) || !match(C, m_APInt(RHSC2)))
85368535
return false;
85378536

8538-
// They must both have samesign flag or not. And sign bits of two RHSCs should
8539-
// match.
8537+
// Sign bits of two RHSCs should match.
85408538
if (cast<ICmpInst>(X)->hasSameSign() &&
8541-
(!cast<ICmpInst>(Y)->hasSameSign() ||
8542-
RHSC1->isNonNegative() != RHSC2->isNonNegative()))
8539+
RHSC1->isNonNegative() != RHSC2->isNonNegative())
85438540
return false;
85448541

85458542
const auto CR1 = ConstantRange::makeExactICmpRegion(Pred1, *RHSC1);

llvm/test/Transforms/InstCombine/select-cmp.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,9 @@ define i1 @test_select_inverse_nonconst4(i64 %x, i64 %y, i64 %z, i1 %cond) {
482482

483483
define i1 @test_select_inverse_samesign_true_arm(i64 %x, i64 %y, i1 %cond) {
484484
; CHECK-LABEL: @test_select_inverse_samesign_true_arm(
485-
; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i64 [[X:%.*]], [[Y:%.*]]
486-
; CHECK-NEXT: [[SEL:%.*]] = xor i1 [[COND:%.*]], [[CMP2]]
485+
; CHECK-NEXT: [[CMP1:%.*]] = icmp samesign ult i64 [[X:%.*]], [[Y:%.*]]
486+
; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i64 [[X]], [[Y]]
487+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMP1]], i1 [[CMP2]]
487488
; CHECK-NEXT: ret i1 [[SEL]]
488489
;
489490
%cmp1 = icmp samesign ult i64 %x, %y
@@ -532,8 +533,9 @@ define i1 @test_select_inverse_samesign_false_arm_rhsc_same_sign(i64 %x, i64 %y,
532533

533534
define i1 @test_select_inverse_samesign_true_arm_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {
534535
; CHECK-LABEL: @test_select_inverse_samesign_true_arm_rhsc_same_sign(
535-
; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i64 [[X:%.*]], 10
536-
; CHECK-NEXT: [[SEL:%.*]] = xor i1 [[COND:%.*]], [[CMP2]]
536+
; CHECK-NEXT: [[CMP1:%.*]] = icmp samesign ult i64 [[X:%.*]], 11
537+
; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i64 [[X]], 10
538+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMP1]], i1 [[CMP2]]
537539
; CHECK-NEXT: ret i1 [[SEL]]
538540
;
539541
%cmp1 = icmp samesign ult i64 %x, 11

0 commit comments

Comments
 (0)