@@ -1201,22 +1201,31 @@ literalt bv_utilst::lt_or_le(
12011201 size_t start;
12021202 size_t i;
12031203
1204- compareBelow = prop.new_variables (bv0.size ());
1205- result = prop.new_variable ();
1206-
12071204 if (rep == representationt::SIGNED)
12081205 {
1206+ if (top0.is_false () && top1.is_true ())
1207+ return const_literal (false );
1208+ else if (top0.is_true () && top1.is_false ())
1209+ return const_literal (true );
1210+
12091211 INVARIANT (
12101212 bv0.size () >= 2 , " signed bitvectors should have at least two bits" );
1211- start = compareBelow.size () - 2 ;
1213+ compareBelow = prop.new_variables (bv0.size () - 1 );
1214+ start = compareBelow.size () - 1 ;
12121215
1213- literalt firstComp=compareBelow[start];
1216+ literalt &firstComp = compareBelow[start];
1217+ if (top0.is_false ())
1218+ firstComp = !top1;
1219+ else if (top0.is_true ())
1220+ firstComp = top1;
1221+ else if (top1.is_false ())
1222+ firstComp = !top0;
1223+ else if (top1.is_true ())
1224+ firstComp = top0;
12141225
1215- // When comparing signs we are comparing the top bit
1216- #ifdef INCLUDE_REDUNDANT_CLAUSES
1217- prop.l_set_to_true (compareBelow[start + 1 ])
1218- #endif
1226+ result = prop.new_variable ();
12191227
1228+ // When comparing signs we are comparing the top bit
12201229 // Four cases...
12211230 prop.lcnf (top0, top1, firstComp); // + + compare needed
12221231 prop.lcnf (top0, !top1, !result); // + - result false and no compare needed
@@ -1231,8 +1240,10 @@ literalt bv_utilst::lt_or_le(
12311240 else
12321241 {
12331242 // Unsigned is much easier
1243+ compareBelow = prop.new_variables (bv0.size () - 1 );
1244+ compareBelow.push_back (const_literal (true ));
12341245 start = compareBelow.size () - 1 ;
1235- prop.l_set_to_true (compareBelow[start] );
1246+ result = prop.new_variable ( );
12361247 }
12371248
12381249 // Determine the output
@@ -1241,6 +1252,16 @@ literalt bv_utilst::lt_or_le(
12411252 i = start;
12421253 do
12431254 {
1255+ if (compareBelow[i].is_false ())
1256+ continue ;
1257+ else if (compareBelow[i].is_true ())
1258+ {
1259+ if (bv0[i].is_false () && bv1[i].is_true ())
1260+ return const_literal (true );
1261+ else if (bv0[i].is_true () && bv1[i].is_false ())
1262+ return const_literal (false );
1263+ }
1264+
12441265 prop.lcnf (!compareBelow[i], bv0[i], !bv1[i], result);
12451266 prop.lcnf (!compareBelow[i], !bv0[i], bv1[i], !result);
12461267 }
0 commit comments