llvm.org GIT mirror llvm / 8ac40dd
Strengthen icmp snuggling by doing 'compare-or-equal-to' to 'compare' first and then range testing second. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35715 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 12 years ago
1 changed file(s) with 25 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
21812181 // Eg., if x = [0, 4) and we're being asked icmp uge %x, 3 then change
21822182 // the predicate to eq.
21832183
2184 // XXX: once we do full PHI handling, modifying the instruction in the
2185 // Forwards visitor will cause missed optimizations.
2186
21842187 ICmpInst::Predicate Pred = IC.getPredicate();
2188
2189 switch (Pred) {
2190 default: break;
2191 case ICmpInst::ICMP_ULE: Pred = ICmpInst::ICMP_ULT; break;
2192 case ICmpInst::ICMP_UGE: Pred = ICmpInst::ICMP_UGT; break;
2193 case ICmpInst::ICMP_SLE: Pred = ICmpInst::ICMP_SLT; break;
2194 case ICmpInst::ICMP_SGE: Pred = ICmpInst::ICMP_SGT; break;
2195 }
2196 if (Pred != IC.getPredicate()) {
2197 VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &IC);
2198 if (VRP.isRelatedBy(IC.getOperand(1), IC.getOperand(0),
2199 ICmpInst::ICMP_NE)) {
2200 ++NumSnuggle;
2201 PS->modified = true;
2202 IC.setPredicate(Pred);
2203 }
2204 }
2205
2206 Pred = IC.getPredicate();
21852207
21862208 if (ConstantInt *Op1 = dyn_cast(IC.getOperand(1))) {
21872209 ConstantInt *NextVal = 0;
2188 switch(Pred) {
2210 switch (Pred) {
21892211 default: break;
21902212 case ICmpInst::ICMP_SLT:
21912213 case ICmpInst::ICMP_ULT:
22132235 IC.eraseFromParent();
22142236 ++NumSnuggle;
22152237 PS->modified = true;
2216 return;
2217 }
2218 }
2219 }
2220
2221 switch(Pred) {
2222 default: return;
2223 case ICmpInst::ICMP_ULE: Pred = ICmpInst::ICMP_ULT; break;
2224 case ICmpInst::ICMP_UGE: Pred = ICmpInst::ICMP_UGT; break;
2225 case ICmpInst::ICMP_SLE: Pred = ICmpInst::ICMP_SLT; break;
2226 case ICmpInst::ICMP_SGE: Pred = ICmpInst::ICMP_SGT; break;
2227 }
2228 VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &IC);
2229 if (VRP.isRelatedBy(IC.getOperand(1), IC.getOperand(0), Pred)) {
2230 ++NumSnuggle;
2231 PS->modified = true;
2232 IC.setPredicate(Pred);
2238 }
2239 }
22332240 }
22342241 }
22352242