[llvm] 580d3a1 - [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: refactor `i1 cond ? i1 x : i1 y` handling
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 06:47:21 PST 2022
Author: Roman Lebedev
Date: 2022-02-10T17:42:56+03:00
New Revision: 580d3a14b2a716f31f4e4bccdb7dce4f09c7c3b7
URL: https://github.com/llvm/llvm-project/commit/580d3a14b2a716f31f4e4bccdb7dce4f09c7c3b7
DIFF: https://github.com/llvm/llvm-project/commit/580d3a14b2a716f31f4e4bccdb7dce4f09c7c3b7.diff
LOG: [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: refactor `i1 cond ? i1 x : i1 y` handling
While that effectively concludes i1 select handling,
that boolean restriction can be lifted later.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 52712757b4ae..86d0bb1249c7 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5994,20 +5994,23 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq(
!FalseVal->getType()->isIntegerTy(1))
return getUnknown(V);
- // i1 cond ? i1 x : i1 C --> C + (umin_seq cond, x + C)
- if (isa<ConstantInt>(FalseVal)) {
- const SCEV *C = getSCEV(FalseVal);
- return getAddExpr(C, getUMinExpr(getSCEV(Cond),
- getAddExpr(C, getSCEV(TrueVal)),
- /*Sequential=*/true));
- }
-
- // i1 cond ? i1 C : i1 y --> C + (umin_seq ~cond, y + C)
- if (isa<ConstantInt>(TrueVal)) {
- const SCEV *C = getSCEV(TrueVal);
- return getAddExpr(C, getUMinExpr(getNotSCEV(getSCEV(Cond)),
- getAddExpr(C, getSCEV(FalseVal)),
- /*Sequential=*/true));
+ // i1 cond ? i1 x : i1 C --> C + (umin_seq cond, x + C)
+ // i1 cond ? i1 C : i1 x --> C + (umin_seq ~cond, x + C)
+ if (isa<ConstantInt>(TrueVal) || isa<ConstantInt>(FalseVal)) {
+ const SCEV *CondExpr = getSCEV(Cond);
+ const SCEV *TrueExpr = getSCEV(TrueVal);
+ const SCEV *FalseExpr = getSCEV(FalseVal);
+ const SCEV *X, *C;
+ if (isa<ConstantInt>(TrueVal)) {
+ CondExpr = getNotSCEV(CondExpr);
+ X = FalseExpr;
+ C = TrueExpr;
+ } else {
+ X = TrueExpr;
+ C = FalseExpr;
+ }
+ return getAddExpr(
+ C, getUMinExpr(CondExpr, getAddExpr(C, X), /*Sequential=*/true));
}
return getUnknown(V);
More information about the llvm-commits
mailing list