[PATCH] D119643: [Transforms] Enhance CorrelatedValuePropagation to handle both values of select
Dmitry Vassiliev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 22 12:12:19 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90a3b3109170: [Transforms] Enhance CorrelatedValuePropagation to handle both values of select (authored by slydiman).
Changed prior to commit:
https://reviews.llvm.org/D119643?vs=408410&id=410608#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119643/new/
https://reviews.llvm.org/D119643
Files:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
Index: llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
===================================================================
--- llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
+++ llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
@@ -179,9 +179,8 @@
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
-;; CorrelatedValuePropagation should handle inverted select condition, but it does not yet.
-;; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[F:%.*]], [[LOOP]] ], [ [[X:%.*]], [[ENTRY:%.*]] ]
-; CHECK-NEXT: [[F:%.*]] = tail call i32* @f(i32* [[PHI]])
+; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[F:%.*]], [[LOOP]] ], [ [[X:%.*]], [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[F]] = tail call i32* @f(i32* [[PHI]])
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32* [[F]], [[Y:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP1]], i32* null, i32* [[F]]
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32* [[SEL]], null
Index: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -245,11 +245,20 @@
// value can never be that constant. In that case replace the incoming
// value with the other value of the select. This often allows us to
// remove the select later.
+
+ // The "false" case
if (auto *C = dyn_cast<Constant>(SI->getFalseValue()))
if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C, From, To, CxtI) ==
LazyValueInfo::False)
return SI->getTrueValue();
+ // The "true" case,
+ // similar to the select "false" case, but try the select "true" value
+ if (auto *C = dyn_cast<Constant>(SI->getTrueValue()))
+ if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C, From, To, CxtI) ==
+ LazyValueInfo::False)
+ return SI->getFalseValue();
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119643.410608.patch
Type: text/x-patch
Size: 1968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220222/1ec7884f/attachment.bin>
More information about the llvm-commits
mailing list