From e13f88d1ff5234946af6349a9a7cf56fcb6c040e Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 18 May 2023 09:42:54 +0100 Subject: [PATCH] Revert "ValueTracking: Handle phi in computeKnownFPClass" This reverts commit cac9e427eb1ff3dabda8ac08968b998c3bc5ab47. Causing crashes in lencod --- llvm/lib/Analysis/ValueTracking.cpp | 41 ---------- llvm/unittests/Analysis/ValueTrackingTest.cpp | 108 -------------------------- 2 files changed, 149 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 906ae81..3b70029 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -5094,47 +5094,6 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, Known, Depth + 1, Q, TLI); break; } - case Instruction::PHI: { - const PHINode *P = cast(Op); - // Unreachable blocks may have zero-operand PHI nodes. - if (P->getNumIncomingValues() == 0) - break; - - // Otherwise take the unions of the known bit sets of the operands, - // taking conservative care to avoid excessive recursion. - if (Depth < MaxAnalysisRecursionDepth - 1) { - // Skip if every incoming value references to ourself. - if (isa_and_nonnull(P->hasConstantValue())) - break; - - bool First = true; - - for (Value *IncValue : P->incoming_values()) { - // Skip direct self references. - if (IncValue == P) - continue; - - KnownFPClass KnownSrc; - // Recurse, but cap the recursion to two levels, because we don't want - // to waste time spinning around in loops. We need at least depth 2 to - // detect known sign bits. - computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc, - MaxAnalysisRecursionDepth - 2, Q, TLI); - - if (First) { - Known = KnownSrc; - First = false; - } else { - Known |= KnownSrc; - } - - if (Known.KnownFPClasses == fcAllFlags) - break; - } - } - - break; - } default: break; } diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp index 3684f6f..c83fb62 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -1630,114 +1630,6 @@ TEST_F(ComputeKnownFPClassTest, FMulNoZero) { expectKnownFPClass(fcAllFlags, std::nullopt, A7); } -TEST_F(ComputeKnownFPClassTest, Phi) { - parseAssembly( - "define float @test(i1 %cond, float nofpclass(nan inf) %arg0, float nofpclass(nan) %arg1) {\n" - "entry:\n" - " br i1 %cond, label %bb0, label %bb1\n" - "bb0:\n" - " br label %ret\n" - "bb1:\n" - " br label %ret\n" - "ret:\n" - " %A = phi float [ %arg0, %bb0 ], [ %arg1, %bb1 ]\n" - " ret float %A\n" - "}\n"); - expectKnownFPClass(~fcNan, std::nullopt); -} - -TEST_F(ComputeKnownFPClassTest, PhiKnownSignFalse) { - parseAssembly( - "declare float @llvm.fabs.f32(float)" - "define float @test(i1 %cond, float nofpclass(nan) %arg0, float nofpclass(nan) %arg1) {\n" - "entry:\n" - " br i1 %cond, label %bb0, label %bb1\n" - "bb0:\n" - " %fabs.arg0 = call float @llvm.fabs.f32(float %arg0)\n" - " br label %ret\n" - "bb1:\n" - " %fabs.arg1 = call float @llvm.fabs.f32(float %arg1)\n" - " br label %ret\n" - "ret:\n" - " %A = phi float [ %fabs.arg0, %bb0 ], [ %fabs.arg1, %bb1 ]\n" - " ret float %A\n" - "}\n"); - expectKnownFPClass(fcPositive, false); -} - -TEST_F(ComputeKnownFPClassTest, PhiKnownSignTrue) { - parseAssembly( - "declare float @llvm.fabs.f32(float)" - "define float @test(i1 %cond, float nofpclass(nan) %arg0, float %arg1) {\n" - "entry:\n" - " br i1 %cond, label %bb0, label %bb1\n" - "bb0:\n" - " %fabs.arg0 = call float @llvm.fabs.f32(float %arg0)\n" - " %fneg.fabs.arg0 = fneg float %fabs.arg0\n" - " br label %ret\n" - "bb1:\n" - " %fabs.arg1 = call float @llvm.fabs.f32(float %arg1)\n" - " %fneg.fabs.arg1 = fneg float %fabs.arg1\n" - " br label %ret\n" - "ret:\n" - " %A = phi float [ %fneg.fabs.arg0, %bb0 ], [ %fneg.fabs.arg1, %bb1 ]\n" - " ret float %A\n" - "}\n"); - expectKnownFPClass(fcNegative | fcNan, true); -} - -TEST_F(ComputeKnownFPClassTest, UnreachablePhi) { - parseAssembly( - "define float @test(float %arg) {\n" - "entry:\n" - " ret float 0.0\n" - "unreachable:\n" - " %A = phi float\n" - " ret float %A\n" - "}\n"); - expectKnownFPClass(fcAllFlags, std::nullopt); -} - -TEST_F(ComputeKnownFPClassTest, SelfPhiOnly) { - parseAssembly( - "define float @test(float %arg) {\n" - "entry:\n" - " ret float 0.0\n" - "loop:\n" - " %A = phi float [ %A, %loop ]\n" - " br label %loop\n" - "}\n"); - expectKnownFPClass(fcAllFlags, std::nullopt); -} - -TEST_F(ComputeKnownFPClassTest, SelfPhiFirstArg) { - parseAssembly( - "define float @test(i1 %cond, float nofpclass(inf) %arg) {\n" - "entry:\n" - " br i1 %cond, label %loop, label %ret\n" - "loop:\n" - " %A = phi float [ %arg, %entry ], [ %A, %loop ]\n" - " br label %loop\n" - "ret:\n" - " ret float %A" - "}\n"); - expectKnownFPClass(~fcInf, std::nullopt); -} - -TEST_F(ComputeKnownFPClassTest, SelfPhiSecondArg) { - parseAssembly( - "define float @test(i1 %cond, float nofpclass(inf) %arg) {\n" - "entry:\n" - " br i1 %cond, label %loop, label %ret\n" - "loop:\n" - " %A = phi float [ %A, %loop ], [ %arg, %entry ]\n" - " br label %loop\n" - "ret:\n" - " ret float %A" - "}\n"); - expectKnownFPClass(~fcInf, std::nullopt); -} - TEST_F(ComputeKnownFPClassTest, CannotBeOrderedLessThanZero) { parseAssembly("define float @test(float %arg) {\n" " %A = fmul float %arg, %arg" -- 2.7.4