[llvm] r369088 - [ValueTracking] Fix recurrence detection to check both PHI operands.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 02:15:02 PDT 2019


Author: fhahn
Date: Fri Aug 16 02:15:02 2019
New Revision: 369088

URL: http://llvm.org/viewvc/llvm-project?rev=369088&view=rev
Log:
[ValueTracking] Fix recurrence detection to check both PHI operands.

Summary:
Currently we fail to compute known bits for recurrences where the
first incoming value is the start value of the recurrence.

Instead of exiting the loop when the first incoming value is not
the step of the recurrence, continue to check the second incoming
value.

The original code uses a loop to handle both cases, but incorrectly
exits instead of continuing.

Reviewers: lebedev.ri, spatel, nikic

Reviewed By: lebedev.ri

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66216

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp
    llvm/trunk/test/Transforms/InstCombine/phi-known-bits-operand-order.ll

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=369088&r1=369087&r2=369088&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Aug 16 02:15:02 2019
@@ -1373,7 +1373,7 @@ static void computeKnownBitsFromOperator
           else if (LR == I)
             L = LL;
           else
-            break;
+            continue; // Check for recurrence with L and R flipped.
           // Ok, we have a PHI of the form L op= R. Check for low
           // zero bits.
           computeKnownBits(R, Known2, Depth + 1, Q);

Modified: llvm/trunk/test/Transforms/InstCombine/phi-known-bits-operand-order.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/phi-known-bits-operand-order.ll?rev=369088&r1=369087&r2=369088&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/phi-known-bits-operand-order.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/phi-known-bits-operand-order.ll Fri Aug 16 02:15:02 2019
@@ -19,8 +19,8 @@ define void @phi_recurrence_start_first(
 ; CHECK-NEXT:    br i1 [[COND_V]], label [[FOR_COND11:%.*]], label [[FOR_COND26]]
 ; CHECK:       for.cond11:
 ; CHECK-NEXT:    [[I_1:%.*]] = phi i32 [ [[START]], [[IF_THEN]] ], [ [[STEP:%.*]], [[FOR_COND11]] ]
-; CHECK-NEXT:    [[CMP13:%.*]] = icmp slt i32 [[I_1]], 100
-; CHECK-NEXT:    [[STEP]] = add nsw i32 [[I_1]], 1
+; CHECK-NEXT:    [[CMP13:%.*]] = icmp ult i32 [[I_1]], 100
+; CHECK-NEXT:    [[STEP]] = add nuw nsw i32 [[I_1]], 1
 ; CHECK-NEXT:    br i1 [[CMP13]], label [[FOR_COND11]], label [[WHILE_END]]
 ; CHECK:       for.cond26:
 ; CHECK-NEXT:    br label [[WHILE_COND]]




More information about the llvm-commits mailing list