[llvm] 665e477 - [ObjC][ARC] Fix non-deterministic behavior in ProvenanceAnalysis
Akira Hatanaka via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 4 21:30:34 PST 2023
Author: Akira Hatanaka
Date: 2023-01-04T21:29:42-08:00
New Revision: 665e47777df17db406c698d57b4f3c28d67c432e
URL: https://github.com/llvm/llvm-project/commit/665e47777df17db406c698d57b4f3c28d67c432e
DIFF: https://github.com/llvm/llvm-project/commit/665e47777df17db406c698d57b4f3c28d67c432e.diff
LOG: [ObjC][ARC] Fix non-deterministic behavior in ProvenanceAnalysis
If the second value passed to relatedSelect is a select, check whether
neither arm of the select is related to the first value.
Added:
Modified:
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
llvm/test/Transforms/ObjCARC/related-check.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
index 845038b8b82e..2fa25a79ae9d 100644
--- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
@@ -42,11 +42,17 @@ bool ProvenanceAnalysis::relatedSelect(const SelectInst *A,
const Value *B) {
// If the values are Selects with the same condition, we can do a more precise
// check: just check for relations between the values on corresponding arms.
- if (const SelectInst *SB = dyn_cast<SelectInst>(B))
+ if (const SelectInst *SB = dyn_cast<SelectInst>(B)) {
if (A->getCondition() == SB->getCondition())
return related(A->getTrueValue(), SB->getTrueValue()) ||
related(A->getFalseValue(), SB->getFalseValue());
+ // Check both arms of B individually. Return false if neither arm is related
+ // to A.
+ if (!(related(SB->getTrueValue(), A) || related(SB->getFalseValue(), A)))
+ return false;
+ }
+
// Check both arms of the Select node individually.
return related(A->getTrueValue(), B) || related(A->getFalseValue(), B);
}
diff --git a/llvm/test/Transforms/ObjCARC/related-check.ll b/llvm/test/Transforms/ObjCARC/related-check.ll
index e09d6b1168b8..6eb96a696d23 100644
--- a/llvm/test/Transforms/ObjCARC/related-check.ll
+++ b/llvm/test/Transforms/ObjCARC/related-check.ll
@@ -132,6 +132,19 @@ define ptr @foo() {
ret ptr %call78
}
+; CHECK-LABEL: define void @test_select(
+; CHECK: call ptr @llvm.objc.retain(
+; CHECK: call void @llvm.objc.release(
+
+define void @test_select(i1 %c0, i1 %c1, ptr %p0, ptr %p1) {
+ %cond = select i1 %c0, ptr %p0, ptr %p1
+ %cond5 = select i1 %c0, ptr %p1, ptr %p0
+ %cond14 = select i1 %c1, ptr %cond5, ptr null
+ call ptr @llvm.objc.retain(ptr %cond14)
+ call void @llvm.objc.release(ptr %cond)
+ ret void
+}
+
declare ptr @bar(ptr)
declare ptr @llvm.objc.retain(ptr)
More information about the llvm-commits
mailing list