From 5d4bd49c4d4c99b033d3dabc87d0048cbd06d4ff Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 16 Aug 2019 09:15:02 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369088 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ValueTracking.cpp | 2 +- test/Transforms/InstCombine/phi-known-bits-operand-order.ll | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 8027c2706ee..127c3dcc35c 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -1373,7 +1373,7 @@ static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known, 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); diff --git a/test/Transforms/InstCombine/phi-known-bits-operand-order.ll b/test/Transforms/InstCombine/phi-known-bits-operand-order.ll index 3ab2dc8e312..e21e388e7dc 100644 --- a/test/Transforms/InstCombine/phi-known-bits-operand-order.ll +++ b/test/Transforms/InstCombine/phi-known-bits-operand-order.ll @@ -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]] -- 2.49.0