@@ -94,6 +94,31 @@ STATISTIC(NumUDivURemsNarrowedExpanded,
94
94
" Number of bound udiv's/urem's expanded" );
95
95
STATISTIC (NumZExt, " Number of non-negative deductions" );
96
96
97
+ static Constant *getConstantAt (Value *V, Instruction *At, LazyValueInfo *LVI) {
98
+ if (Constant *C = LVI->getConstant (V, At))
99
+ return C;
100
+
101
+ // TODO: The following really should be sunk inside LVI's core algorithm, or
102
+ // at least the outer shims around such.
103
+ auto *C = dyn_cast<CmpInst>(V);
104
+ if (!C)
105
+ return nullptr ;
106
+
107
+ Value *Op0 = C->getOperand (0 );
108
+ Constant *Op1 = dyn_cast<Constant>(C->getOperand (1 ));
109
+ if (!Op1)
110
+ return nullptr ;
111
+
112
+ LazyValueInfo::Tristate Result = LVI->getPredicateAt (
113
+ C->getPredicate (), Op0, Op1, At, /* UseBlockValue=*/ false );
114
+ if (Result == LazyValueInfo::Unknown)
115
+ return nullptr ;
116
+
117
+ return (Result == LazyValueInfo::True)
118
+ ? ConstantInt::getTrue (C->getContext ())
119
+ : ConstantInt::getFalse (C->getContext ());
120
+ }
121
+
97
122
static bool processSelect (SelectInst *S, LazyValueInfo *LVI) {
98
123
if (S->getType ()->isVectorTy () || isa<Constant>(S->getCondition ()))
99
124
return false ;
@@ -106,7 +131,7 @@ static bool processSelect(SelectInst *S, LazyValueInfo *LVI) {
106
131
C = LVI->getConstantOnEdge (S->getCondition (), PN->getIncomingBlock (U),
107
132
I->getParent (), I);
108
133
else
109
- C = LVI-> getConstant (S->getCondition (), I);
134
+ C = getConstantAt (S->getCondition (), I, LVI );
110
135
111
136
auto *CI = dyn_cast_or_null<ConstantInt>(C);
112
137
if (!CI)
@@ -1109,30 +1134,6 @@ static bool processAnd(BinaryOperator *BinOp, LazyValueInfo *LVI) {
1109
1134
return true ;
1110
1135
}
1111
1136
1112
-
1113
- static Constant *getConstantAt (Value *V, Instruction *At, LazyValueInfo *LVI) {
1114
- if (Constant *C = LVI->getConstant (V, At))
1115
- return C;
1116
-
1117
- // TODO: The following really should be sunk inside LVI's core algorithm, or
1118
- // at least the outer shims around such.
1119
- auto *C = dyn_cast<CmpInst>(V);
1120
- if (!C) return nullptr ;
1121
-
1122
- Value *Op0 = C->getOperand (0 );
1123
- Constant *Op1 = dyn_cast<Constant>(C->getOperand (1 ));
1124
- if (!Op1) return nullptr ;
1125
-
1126
- LazyValueInfo::Tristate Result = LVI->getPredicateAt (
1127
- C->getPredicate (), Op0, Op1, At, /* UseBlockValue=*/ false );
1128
- if (Result == LazyValueInfo::Unknown)
1129
- return nullptr ;
1130
-
1131
- return (Result == LazyValueInfo::True) ?
1132
- ConstantInt::getTrue (C->getContext ()) :
1133
- ConstantInt::getFalse (C->getContext ());
1134
- }
1135
-
1136
1137
static bool runImpl (Function &F, LazyValueInfo *LVI, DominatorTree *DT,
1137
1138
const SimplifyQuery &SQ) {
1138
1139
bool FnChanged = false ;
0 commit comments