1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[ValueTracking] Don't require strictly positive for mul nsw recurrence

Just like in the mul nuw case, it's sufficient that the step is
non-zero. If the step is negative, then the values will jump
between positive and negative, "crossing" zero, but the value of
the recurrence is never actually zero.
This commit is contained in:
Nikita Popov 2021-04-14 19:37:47 +02:00
parent 5a5a9545b4
commit e6b1858425
2 changed files with 3 additions and 5 deletions

View File

@ -2231,9 +2231,8 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
(BO->hasNoSignedWrap() && match(Step, m_APInt(StepC)) && (BO->hasNoSignedWrap() && match(Step, m_APInt(StepC)) &&
StartC->isNegative() == StepC->isNegative()); StartC->isNegative() == StepC->isNegative());
case Instruction::Mul: case Instruction::Mul:
return match(Step, m_APInt(StepC)) && return (BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap()) &&
((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) || match(Step, m_APInt(StepC)) && !StepC->isNullValue();
(BO->hasNoSignedWrap() && StepC->isStrictlyPositive()));
case Instruction::Shl: case Instruction::Shl:
return BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap(); return BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap();
case Instruction::AShr: case Instruction::AShr:

View File

@ -339,8 +339,7 @@ define i1 @test_mul_nsw_negative_step(i8 %n) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]] ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]] ; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit: ; CHECK: exit:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], 0 ; CHECK-NEXT: ret i1 false
; CHECK-NEXT: ret i1 [[CMP]]
; ;
entry: entry:
br label %loop br label %loop