llvm.org GIT mirror llvm / a995d92
Support NE inequality in ValueRanges. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35724 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 12 years ago
1 changed file(s) with 58 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
948948 update(V, CR, Subtree);
949949 }
950950
951 void addNotEquals(Value *V1, Value *V2, ETNode *Subtree, VRPSolver *VRP) {
952 uint32_t W = typeToWidth(V1->getType());
953 if (!W) return;
954
955 ConstantRange CR1 = rangeFromValue(V1, Subtree, W);
956 ConstantRange CR2 = rangeFromValue(V2, Subtree, W);
957
958 if (const APInt *I = CR1.getSingleElement()) {
959 if (CR2.isFullSet()) {
960 ConstantRange NewCR2(CR1.getUpper(), CR1.getLower());
961 applyRange(V2, NewCR2, Subtree, VRP);
962 } else if (*I == CR2.getLower()) {
963 APInt NewLower = CR2.getLower() + 1,
964 NewUpper = CR2.getUpper();
965 if (NewLower == NewUpper)
966 NewLower = NewUpper = APInt::getMinValue(W);
967
968 ConstantRange NewCR2(NewLower, NewUpper);
969 applyRange(V2, NewCR2, Subtree, VRP);
970 } else if (*I == CR2.getUpper() - 1) {
971 APInt NewLower = CR2.getLower(),
972 NewUpper = CR2.getUpper() - 1;
973 if (NewLower == NewUpper)
974 NewLower = NewUpper = APInt::getMinValue(W);
975
976 ConstantRange NewCR2(NewLower, NewUpper);
977 applyRange(V2, NewCR2, Subtree, VRP);
978 }
979 }
980
981 if (const APInt *I = CR2.getSingleElement()) {
982 if (CR1.isFullSet()) {
983 ConstantRange NewCR1(CR2.getUpper(), CR2.getLower());
984 applyRange(V1, NewCR1, Subtree, VRP);
985 } else if (*I == CR1.getLower()) {
986 APInt NewLower = CR1.getLower() + 1,
987 NewUpper = CR1.getUpper();
988 if (NewLower == NewUpper)
989 NewLower = NewUpper = APInt::getMinValue(W);
990
991 ConstantRange NewCR1(NewLower, NewUpper);
992 applyRange(V1, NewCR1, Subtree, VRP);
993 } else if (*I == CR1.getUpper() - 1) {
994 APInt NewLower = CR1.getLower(),
995 NewUpper = CR1.getUpper() - 1;
996 if (NewLower == NewUpper)
997 NewLower = NewUpper = APInt::getMinValue(W);
998
999 ConstantRange NewCR1(NewLower, NewUpper);
1000 applyRange(V1, NewCR1, Subtree, VRP);
1001 }
1002 }
1003 }
1004
9511005 void addInequality(Value *V1, Value *V2, ETNode *Subtree, LatticeVal LV,
9521006 VRPSolver *VRP) {
9531007 assert(!isRelatedBy(V1, V2, Subtree, LV) && "Asked to do useless work.");
9551009 assert(isCanonical(V1, Subtree, VRP) && "Value not canonical.");
9561010 assert(isCanonical(V2, Subtree, VRP) && "Value not canonical.");
9571011
958 if (LV == NE) return; // we can't represent those.
959 // XXX: except in the case where isSingleElement and equal to either
960 // Lower or Upper. That's probably not profitable. (Type::Int1Ty?)
1012 if (LV == NE) {
1013 addNotEquals(V1, V2, Subtree, VRP);
1014 return;
1015 }
9611016
9621017 uint32_t W = typeToWidth(V1->getType());
9631018 if (!W) return;