[PATCH] D75808: [ValueTracking] isKnownNonZero, computeKnownBits for freeze
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 16:08:14 PDT 2020
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6183d0f028c: [ValueTracking] isKnownNonZero, computeKnownBits for freeze (authored by aqjune).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75808/new/
https://reviews.llvm.org/D75808
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/known-non-zero.ll
llvm/unittests/Analysis/ValueTrackingTest.cpp
Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1059,6 +1059,24 @@
EXPECT_EQ(Known.One.getZExtValue(), 0u);
}
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsFreeze) {
+ parseAssembly("define void @test() {\n"
+ " %m = call i32 @any_num()\n"
+ " %A = freeze i32 %m\n"
+ " %n = and i32 %m, 31\n"
+ " %c = icmp eq i32 %n, 0\n"
+ " call void @llvm.assume(i1 %c)\n"
+ " ret void\n"
+ "}\n"
+ "declare void @llvm.assume(i1)\n"
+ "declare i32 @any_num()\n");
+ AssumptionCache AC(*F);
+ KnownBits Known = computeKnownBits(A, M->getDataLayout(), /* Depth */ 0, &AC,
+ F->front().getTerminator());
+ EXPECT_EQ(Known.Zero.getZExtValue(), 31u);
+ EXPECT_EQ(Known.One.getZExtValue(), 0u);
+}
+
class IsBytewiseValueTest : public ValueTrackingTest,
public ::testing::WithParamInterface<
std::pair<const char *, const char *>> {
Index: llvm/test/Transforms/InstSimplify/known-non-zero.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/known-non-zero.ll
+++ llvm/test/Transforms/InstSimplify/known-non-zero.ll
@@ -145,3 +145,24 @@
%inc = add nuw nsw i32 %shift.0, 1
br label %for.cond
}
+
+define i1 @freeze_nonzero(i8 %x, i8 %mask) {
+; CHECK-LABEL: @freeze_nonzero(
+; CHECK-NEXT: [[Y:%.*]] = or i8 [[X:%.*]], [[MASK:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[Y]], 0
+; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
+; CHECK: A:
+; CHECK-NEXT: ret i1 false
+; CHECK: B:
+; CHECK-NEXT: ret i1 false
+;
+ %y = or i8 %x, %mask
+ %c = icmp ne i8 %y, 0
+ br i1 %c, label %A, label %B
+A:
+ %fr = freeze i8 %y
+ %c2 = icmp eq i8 %fr, 0
+ ret i1 %c2
+B:
+ ret i1 0
+}
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -1872,6 +1872,10 @@
}
}
break;
+ case Instruction::Freeze:
+ if (isGuaranteedNotToBePoison(I->getOperand(0), Q.CxtI, Q.DT, Depth + 1))
+ computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
+ break;
}
}
@@ -2577,6 +2581,13 @@
return isKnownNonZero(Vec, DemandedVecElts, Depth, Q);
}
}
+ // Freeze
+ else if (const FreezeInst *FI = dyn_cast<FreezeInst>(V)) {
+ auto *Op = FI->getOperand(0);
+ if (isKnownNonZero(Op, Depth, Q) &&
+ isGuaranteedNotToBePoison(Op, Q.CxtI, Q.DT, Depth))
+ return true;
+ }
KnownBits Known(BitWidth);
computeKnownBits(V, DemandedElts, Known, Depth, Q);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75808.290841.patch
Type: text/x-patch
Size: 2947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/c8d25c38/attachment.bin>
More information about the llvm-commits
mailing list