319
331
isl_map_free(map2);
335
__isl_give isl_val *(*op)(__isl_take isl_val *v);
339
{ &isl_val_neg, "0", "0" },
340
{ &isl_val_abs, "0", "0" },
341
{ &isl_val_2exp, "0", "1" },
342
{ &isl_val_floor, "0", "0" },
343
{ &isl_val_ceil, "0", "0" },
344
{ &isl_val_neg, "1", "-1" },
345
{ &isl_val_neg, "-1", "1" },
346
{ &isl_val_neg, "1/2", "-1/2" },
347
{ &isl_val_neg, "-1/2", "1/2" },
348
{ &isl_val_neg, "infty", "-infty" },
349
{ &isl_val_neg, "-infty", "infty" },
350
{ &isl_val_neg, "NaN", "NaN" },
351
{ &isl_val_abs, "1", "1" },
352
{ &isl_val_abs, "-1", "1" },
353
{ &isl_val_abs, "1/2", "1/2" },
354
{ &isl_val_abs, "-1/2", "1/2" },
355
{ &isl_val_abs, "infty", "infty" },
356
{ &isl_val_abs, "-infty", "infty" },
357
{ &isl_val_abs, "NaN", "NaN" },
358
{ &isl_val_floor, "1", "1" },
359
{ &isl_val_floor, "-1", "-1" },
360
{ &isl_val_floor, "1/2", "0" },
361
{ &isl_val_floor, "-1/2", "-1" },
362
{ &isl_val_floor, "infty", "infty" },
363
{ &isl_val_floor, "-infty", "-infty" },
364
{ &isl_val_floor, "NaN", "NaN" },
365
{ &isl_val_ceil, "1", "1" },
366
{ &isl_val_ceil, "-1", "-1" },
367
{ &isl_val_ceil, "1/2", "1" },
368
{ &isl_val_ceil, "-1/2", "0" },
369
{ &isl_val_ceil, "infty", "infty" },
370
{ &isl_val_ceil, "-infty", "-infty" },
371
{ &isl_val_ceil, "NaN", "NaN" },
372
{ &isl_val_2exp, "-3", "1/8" },
373
{ &isl_val_2exp, "-1", "1/2" },
374
{ &isl_val_2exp, "1", "2" },
375
{ &isl_val_2exp, "2", "4" },
376
{ &isl_val_2exp, "3", "8" },
379
/* Perform some basic tests of unary operations on isl_val objects.
381
static int test_un_val(isl_ctx *ctx)
385
__isl_give isl_val *(*fn)(__isl_take isl_val *v);
388
for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
389
v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
390
res = isl_val_read_from_str(ctx, val_un_tests[i].res);
391
fn = val_un_tests[i].op;
393
if (isl_val_is_nan(res))
394
ok = isl_val_is_nan(v);
396
ok = isl_val_eq(v, res);
402
isl_die(ctx, isl_error_unknown,
403
"unexpected result", return -1);
410
__isl_give isl_val *(*fn)(__isl_take isl_val *v1,
411
__isl_take isl_val *v2);
413
['+'] = { &isl_val_add },
414
['-'] = { &isl_val_sub },
415
['*'] = { &isl_val_mul },
416
['/'] = { &isl_val_div },
417
['g'] = { &isl_val_gcd },
418
['m'] = { &isl_val_min },
419
['M'] = { &isl_val_max },
427
} val_bin_tests[] = {
428
{ "0", '+', "0", "0" },
429
{ "1", '+', "0", "1" },
430
{ "1", '+', "1", "2" },
431
{ "1", '-', "1", "0" },
432
{ "1", '*', "1", "1" },
433
{ "1", '/', "1", "1" },
434
{ "2", '*', "3", "6" },
435
{ "2", '*', "1/2", "1" },
436
{ "2", '*', "1/3", "2/3" },
437
{ "2/3", '*', "3/5", "2/5" },
438
{ "2/3", '*', "7/5", "14/15" },
439
{ "2", '/', "1/2", "4" },
440
{ "-2", '/', "-1/2", "4" },
441
{ "-2", '/', "1/2", "-4" },
442
{ "2", '/', "-1/2", "-4" },
443
{ "2", '/', "2", "1" },
444
{ "2", '/', "3", "2/3" },
445
{ "2/3", '/', "5/3", "2/5" },
446
{ "2/3", '/', "5/7", "14/15" },
447
{ "0", '/', "0", "NaN" },
448
{ "42", '/', "0", "NaN" },
449
{ "-42", '/', "0", "NaN" },
450
{ "infty", '/', "0", "NaN" },
451
{ "-infty", '/', "0", "NaN" },
452
{ "NaN", '/', "0", "NaN" },
453
{ "0", '/', "NaN", "NaN" },
454
{ "42", '/', "NaN", "NaN" },
455
{ "-42", '/', "NaN", "NaN" },
456
{ "infty", '/', "NaN", "NaN" },
457
{ "-infty", '/', "NaN", "NaN" },
458
{ "NaN", '/', "NaN", "NaN" },
459
{ "0", '/', "infty", "0" },
460
{ "42", '/', "infty", "0" },
461
{ "-42", '/', "infty", "0" },
462
{ "infty", '/', "infty", "NaN" },
463
{ "-infty", '/', "infty", "NaN" },
464
{ "NaN", '/', "infty", "NaN" },
465
{ "0", '/', "-infty", "0" },
466
{ "42", '/', "-infty", "0" },
467
{ "-42", '/', "-infty", "0" },
468
{ "infty", '/', "-infty", "NaN" },
469
{ "-infty", '/', "-infty", "NaN" },
470
{ "NaN", '/', "-infty", "NaN" },
471
{ "1", '-', "1/3", "2/3" },
472
{ "1/3", '+', "1/2", "5/6" },
473
{ "1/2", '+', "1/2", "1" },
474
{ "3/4", '-', "1/4", "1/2" },
475
{ "1/2", '-', "1/3", "1/6" },
476
{ "infty", '+', "42", "infty" },
477
{ "infty", '+', "infty", "infty" },
478
{ "42", '+', "infty", "infty" },
479
{ "infty", '-', "infty", "NaN" },
480
{ "infty", '*', "infty", "infty" },
481
{ "infty", '*', "-infty", "-infty" },
482
{ "-infty", '*', "infty", "-infty" },
483
{ "-infty", '*', "-infty", "infty" },
484
{ "0", '*', "infty", "NaN" },
485
{ "1", '*', "infty", "infty" },
486
{ "infty", '*', "0", "NaN" },
487
{ "infty", '*', "42", "infty" },
488
{ "42", '-', "infty", "-infty" },
489
{ "infty", '+', "-infty", "NaN" },
490
{ "4", 'g', "6", "2" },
491
{ "5", 'g', "6", "1" },
492
{ "42", 'm', "3", "3" },
493
{ "42", 'M', "3", "42" },
494
{ "3", 'm', "42", "3" },
495
{ "3", 'M', "42", "42" },
496
{ "42", 'm', "infty", "42" },
497
{ "42", 'M', "infty", "infty" },
498
{ "42", 'm', "-infty", "-infty" },
499
{ "42", 'M', "-infty", "42" },
500
{ "42", 'm', "NaN", "NaN" },
501
{ "42", 'M', "NaN", "NaN" },
502
{ "infty", 'm', "-infty", "-infty" },
503
{ "infty", 'M', "-infty", "infty" },
506
/* Perform some basic tests of binary operations on isl_val objects.
508
static int test_bin_val(isl_ctx *ctx)
511
isl_val *v1, *v2, *res;
512
__isl_give isl_val *(*fn)(__isl_take isl_val *v1,
513
__isl_take isl_val *v2);
516
for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
517
v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
518
v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
519
res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
520
fn = val_bin_op[val_bin_tests[i].op].fn;
522
if (isl_val_is_nan(res))
523
ok = isl_val_is_nan(v1);
525
ok = isl_val_eq(v1, res);
531
isl_die(ctx, isl_error_unknown,
532
"unexpected result", return -1);
538
/* Perform some basic tests on isl_val objects.
540
static int test_val(isl_ctx *ctx)
542
if (test_un_val(ctx) < 0)
544
if (test_bin_val(ctx) < 0)
322
549
static int test_div(isl_ctx *ctx)
930
int test_coalesce(struct isl_ctx *ctx)
1212
/* Inputs for coalescing tests.
1213
* "str" is a string representation of the input set.
1214
* "single_disjunct" is set if we expect the result to consist of
1215
* a single disjunct.
1218
int single_disjunct;
932
1219
const char *str;
933
struct isl_set *set, *set2;
934
struct isl_map *map, *map2;
936
set = isl_set_read_from_str(ctx,
937
"{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
938
"y >= x & x >= 2 & 5 >= y }");
939
set = isl_set_coalesce(set);
940
assert(set && set->n == 1);
943
set = isl_set_read_from_str(ctx,
944
"{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
945
"x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
946
set = isl_set_coalesce(set);
947
assert(set && set->n == 1);
950
set = isl_set_read_from_str(ctx,
951
"{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
952
"x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
953
set = isl_set_coalesce(set);
954
assert(set && set->n == 2);
957
set = isl_set_read_from_str(ctx,
958
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
959
"y >= 0 & x >= 6 & x <= 10 & y <= x}");
960
set = isl_set_coalesce(set);
961
assert(set && set->n == 1);
964
set = isl_set_read_from_str(ctx,
965
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
966
"y >= 0 & x >= 7 & x <= 10 & y <= x}");
967
set = isl_set_coalesce(set);
968
assert(set && set->n == 2);
971
set = isl_set_read_from_str(ctx,
972
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
973
"y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}");
974
set = isl_set_coalesce(set);
975
assert(set && set->n == 2);
978
set = isl_set_read_from_str(ctx,
979
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
980
"y >= 0 & x = 6 & y <= 6}");
981
set = isl_set_coalesce(set);
982
assert(set && set->n == 1);
985
set = isl_set_read_from_str(ctx,
986
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
987
"y >= 0 & x = 7 & y <= 6}");
988
set = isl_set_coalesce(set);
989
assert(set && set->n == 2);
992
set = isl_set_read_from_str(ctx,
993
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
994
"y >= 0 & x = 6 & y <= 5}");
995
set = isl_set_coalesce(set);
996
assert(set && set->n == 1);
997
set2 = isl_set_read_from_str(ctx,
998
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
999
"y >= 0 & x = 6 & y <= 5}");
1000
assert(isl_set_is_equal(set, set2));
1004
set = isl_set_read_from_str(ctx,
1005
"{[x,y]: y >= 0 & x <= 5 & y <= x or "
1006
"y >= 0 & x = 6 & y <= 7}");
1007
set = isl_set_coalesce(set);
1008
assert(set && set->n == 2);
1011
set = isl_set_read_from_str(ctx,
1012
"[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
1013
set = isl_set_coalesce(set);
1014
assert(set && set->n == 1);
1015
set2 = isl_set_read_from_str(ctx,
1016
"[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
1017
assert(isl_set_is_equal(set, set2));
1021
set = isl_set_read_from_str(ctx,
1022
"{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
1023
set = isl_set_coalesce(set);
1024
set2 = isl_set_read_from_str(ctx,
1025
"{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
1026
assert(isl_set_is_equal(set, set2));
1030
set = isl_set_read_from_str(ctx,
1031
"[n] -> { [i] : 1 <= i and i <= n - 1 or "
1032
"2 <= i and i <= n }");
1033
set = isl_set_coalesce(set);
1034
assert(set && set->n == 1);
1035
set2 = isl_set_read_from_str(ctx,
1036
"[n] -> { [i] : 1 <= i and i <= n - 1 or "
1037
"2 <= i and i <= n }");
1038
assert(isl_set_is_equal(set, set2));
1042
map = isl_map_read_from_str(ctx,
1043
"[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1044
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1045
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1046
"4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1047
"o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1048
"i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1049
"4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1050
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1051
"[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1052
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1053
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1054
"4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1055
"2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1056
"2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1057
"i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1058
"4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1059
"o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1060
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1061
map = isl_map_coalesce(map);
1062
map2 = isl_map_read_from_str(ctx,
1063
"[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1064
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1065
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1066
"4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1067
"o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1068
"i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1069
"4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1070
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1071
"[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1072
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1073
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1074
"4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1075
"2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1076
"2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1077
"i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1078
"4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1079
"o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1080
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1081
assert(isl_map_is_equal(map, map2));
1085
str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1220
} coalesce_tests[] = {
1221
{ 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1222
"y >= x & x >= 2 & 5 >= y }" },
1223
{ 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1224
"x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1225
{ 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1226
"x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1227
{ 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1228
"y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1229
{ 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1230
"y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1231
{ 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1232
"y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1233
{ 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1234
{ 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1235
{ 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1236
{ 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1237
{ 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1238
{ 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1239
{ 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1240
{ 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1241
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1242
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1243
"4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1244
"o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1245
"i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1246
"4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1247
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1248
"[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1249
"e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1250
"e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1251
"4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1252
"2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1253
"2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1254
"i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1255
"4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1256
"o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1257
"4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1258
{ 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1086
1259
"o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1087
1260
"(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1088
"o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
1089
map = isl_map_read_from_str(ctx, str);
1090
map = isl_map_coalesce(map);
1091
map2 = isl_map_read_from_str(ctx, str);
1092
assert(isl_map_is_equal(map, map2));
1096
str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
1097
"[o0, o1, o2, o3, o4, o5, o6] : "
1261
"o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1262
{ 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1263
"[o0, o1, o2, o3, o4, o5, o6]] : "
1098
1264
"(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1099
1265
"o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1100
1266
"o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1107
1273
"(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1108
1274
"o6 >= i3 + i6 - o3 and M >= 0 and "
1109
1275
"2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1110
"o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
1111
map = isl_map_read_from_str(ctx, str);
1112
map = isl_map_coalesce(map);
1113
map2 = isl_map_read_from_str(ctx, str);
1114
assert(isl_map_is_equal(map, map2));
1118
str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1276
"o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1277
{ 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1119
1278
"(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1120
1279
"(o0 = 0 and M >= 2 and N >= 3) or "
1121
"(M = 0 and o0 = 0 and N >= 3) }";
1122
map = isl_map_read_from_str(ctx, str);
1123
map = isl_map_coalesce(map);
1124
map2 = isl_map_read_from_str(ctx, str);
1125
assert(isl_map_is_equal(map, map2));
1129
str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1130
"i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1131
"(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1132
"i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1133
map = isl_map_read_from_str(ctx, str);
1134
map = isl_map_coalesce(map);
1135
map2 = isl_map_read_from_str(ctx, str);
1136
assert(isl_map_is_equal(map, map2));
1140
test_coalesce_set(ctx,
1141
"[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1142
"(i1 = M and M >= 1) }", 0);
1143
test_coalesce_set(ctx,
1144
"{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1145
test_coalesce_set(ctx,
1146
"{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1147
"(y = 3 and x = 1) }", 1);
1148
test_coalesce_set(ctx,
1149
"[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1280
"(M = 0 and o0 = 0 and N >= 3) }" },
1281
{ 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1282
"i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1283
"(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1284
"i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1285
{ 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1286
{ 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1287
{ 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1288
"(y = 3 and x = 1) }" },
1289
{ 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1150
1290
"i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1151
1291
"i1 <= M and i3 <= M and i4 <= M) or "
1152
1292
"(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1153
1293
"i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1154
"i4 <= -1 + M) }", 1);
1155
test_coalesce_set(ctx,
1156
"{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1157
"(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1158
if (test_coalesce_unbounded_wrapping(ctx) < 0)
1160
if (test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
1162
if (test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
1164
if (test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
1166
if (test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
1168
if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
1170
if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
1172
if (test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1174
if (test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1176
if (test_coalesce_set(ctx, "{ [a, b] : exists e : 2e = a and "
1177
"a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
1179
if (test_coalesce_set(ctx,
1180
"{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1294
"i4 <= -1 + M) }" },
1295
{ 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1296
"(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1297
{ 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1298
{ 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1299
{ 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1300
{ 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1301
{ 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1302
{ 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1303
{ 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1304
{ 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1305
{ 0, "{ [a, b] : exists e : 2e = a and "
1306
"a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1307
{ 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1181
1308
"j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1182
1309
"j >= 1 and j' <= i + j - i' and i >= 1; "
1183
"[1, 1, 1, 1] }", 0) < 0)
1185
if (test_coalesce_set(ctx, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1186
"[i,j] : exists a : j = 3a }", 1) < 0)
1311
{ 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1312
"[i,j] : exists a : j = 3a }" },
1313
{ 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1314
"c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1316
"(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1317
"b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1318
{ 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1319
"c <= 6 + 8a and a >= 3; "
1320
"[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1321
"c <= 7 + 8a and a >= 3 and a <= 4 }" },
1322
{ 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1323
"[x,0] : 3 <= x <= 4 }" },
1324
{ 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1325
"[x,0] : 4 <= x <= 5 }" },
1326
{ 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1327
"[x,0] : 3 <= x <= 5 }" },
1328
{ 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1329
"[x,0] : 3 <= x <= 4 }" },
1330
{ 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1332
"[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1335
/* Test the functionality of isl_set_coalesce.
1336
* That is, check that the output is always equal to the input
1337
* and in some cases that the result consists of a single disjunct.
1339
static int test_coalesce(struct isl_ctx *ctx)
1343
for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
1344
const char *str = coalesce_tests[i].str;
1345
int check_one = coalesce_tests[i].single_disjunct;
1346
if (test_coalesce_set(ctx, str, check_one) < 0)
1350
if (test_coalesce_unbounded_wrapping(ctx) < 0)
3748
4278
if (test_ast_gen4(ctx) < 0)
4280
if (test_ast_gen5(ctx) < 0)
4285
/* Check if dropping output dimensions from an isl_pw_multi_aff
4288
static int test_pw_multi_aff(isl_ctx *ctx)
4291
isl_pw_multi_aff *pma1, *pma2;
4294
str = "{ [i,j] -> [i+j, 4i-j] }";
4295
pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
4296
str = "{ [i,j] -> [4i-j] }";
4297
pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
4299
pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
4301
equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
4303
isl_pw_multi_aff_free(pma1);
4304
isl_pw_multi_aff_free(pma2);
4308
isl_die(ctx, isl_error_unknown,
4309
"expressions not equal", return -1);
4314
/* This is a regression test for a bug where isl_basic_map_simplify
4315
* would end up in an infinite loop. In particular, we construct
4316
* an empty basic set that is not obviously empty.
4317
* isl_basic_set_is_empty marks the basic set as empty.
4318
* After projecting out i3, the variable can be dropped completely,
4319
* but isl_basic_map_simplify refrains from doing so if the basic set
4320
* is empty and would end up in an infinite loop if it didn't test
4321
* explicitly for empty basic maps in the outer loop.
4323
static int test_simplify(isl_ctx *ctx)
4326
isl_basic_set *bset;
4329
str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4330
"i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4331
"25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4333
bset = isl_basic_set_read_from_str(ctx, str);
4334
empty = isl_basic_set_is_empty(bset);
4335
bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
4336
isl_basic_set_free(bset);
4340
isl_die(ctx, isl_error_unknown,
4341
"basic set should be empty", return -1);
4346
/* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4347
* with gbr context would fail to disable the use of the shifted tableau
4348
* when transferring equalities for the input to the context, resulting
4349
* in invalid sample values.
4351
static int test_partial_lexmin(isl_ctx *ctx)
4354
isl_basic_set *bset;
4355
isl_basic_map *bmap;
4358
str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4359
bmap = isl_basic_map_read_from_str(ctx, str);
4360
str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4361
bset = isl_basic_set_read_from_str(ctx, str);
4362
map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
4371
/* Check that the variable compression performed on the existentially
4372
* quantified variables inside isl_basic_set_compute_divs is not confused
4373
* by the implicit equalities among the parameters.
4375
static int test_compute_divs(isl_ctx *ctx)
4378
isl_basic_set *bset;
4381
str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4382
"b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4383
"2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4384
"32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4385
bset = isl_basic_set_read_from_str(ctx, str);
4386
set = isl_basic_set_compute_divs(bset);