llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.84k stars 11.46k forks source link

[mlir] flattener.walkPostOrder exceeds stack #100059

Open jpienaar opened 1 month ago

jpienaar commented 1 month ago

https://github.com/llvm/llvm-project/blame/main/mlir/lib/IR/AffineExpr.cpp#L1561 results in recursing while walking the operation resulting in segfault 

Was using something akin to

{test = [affine_map\<(d0)[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, s32, s33, s34, s35, s36, s37, s38, s39, s40, s41, s42, s43, s44, s45, s46, s47, s48, s49, s50, s51, s52, s53, s54, s55, s56, s57, s58, s59, s60, s61, s62, s63, s64, s65, s66, s67, s68, s69, s70, s71, s72, s73, s74, s75, s76, s77, s78, s79, s80, s81, s82, s83, s84, s85, s86, s87, s88, s89, s90, s91, s92, s93, s94, s95, s96, s97, s98, s99] -> (s0 * 4428 + s1 * 394 - s2 * 5572 - s3 * 9275 + s4 * 4108 + s5 * 6656 + s6 * 7912 - s7 * 1953 - s8 * 7438 - s9 * 7540 - s10 * 131 - s11 * 4508 + s12 * 1560 - s13 * 5586 + s14 * 8159 + s15 * 932 - s16 * 8506 - s17 * 3325 - s18 * 5040 + s19 * 7930 - s20 * 3091 + s21 * 2389 + s22 * 9877 + s23 * 1941 - s24 * 8175 - s25 * 9956 + s26 * 6537 + s27 * 8439 - s28 * 262 - s29 * 8363 - s30 * 34 + s31 * 5919 + s32 * 7510 - s33 * 2022 + s34 * 9986 - s35 * 2417 + s36 * 892 + s37 * 6307 - s38 * 8347 + s39 * 3130 + s40 * 6385 + s41 * 2693 - s42 * 4571 - s43 * 3279 - s44 * 7035 + s45 * 5372 - s46 * 3948 - s47 * 5548 - s48 * 2615 - s49 * 1547 + s50 * 8 - s51 * 4483 - s52 * 9041 + s53 * 2074 + s54 * 6123 + s55 * 9648 - s56 * 4958 - s57 * 8982 + s58 * 8436 - s59 * 7755 - s60 * 3659 + s61 * 3272 + s62 * 6137 + s63 * 1058 + s64 * 3285 - s65 * 985 + s66 * 1658 + s67 * 8626 - s68 * 7975 - s69 * 9610 - s70 * 8678 - s71 * 768 - s72 * 2846 - s73 * 5229 + s74 * 1065 + s75 * 6757 + s76 * 8854 - s77 * 7809 - s78 * 2659 - s79 * 592 - s80 * 5537 - s81 * 7616 + s82 * 2033 - s83 * 5121 - s84 * 9005 - s85 * 8493 + s86 * 4449 - s87 * 5269 - s88 * 8447 + s89 * 8878 + s90 * 1967 + s91 * 1938 + s92 * 2483 - s93 * 6314 + s94 * 7379 + s95 * 6090 + s96 * 1264 - s97 * 5371 + s98 * 1766 - s99 * 2218)>]}

Is this just not meant to handle larger equations?

llvmbot commented 1 month ago

@llvm/issue-subscribers-mlir-affine

Author: Jacques Pienaar (jpienaar)

[https://github.com/llvm/llvm-project/blame/main/mlir/lib/IR/AffineExpr.cpp#L1561](https://github.com/llvm/llvm-project/blame/main/mlir/lib/IR/AffineExpr.cpp#L1561) results in recursing while walking the operation resulting in segfault  Was using something akin to {test = \[affine\_map\<(d0)\[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, s32, s33, s34, s35, s36, s37, s38, s39, s40, s41, s42, s43, s44, s45, s46, s47, s48, s49, s50, s51, s52, s53, s54, s55, s56, s57, s58, s59, s60, s61, s62, s63, s64, s65, s66, s67, s68, s69, s70, s71, s72, s73, s74, s75, s76, s77, s78, s79, s80, s81, s82, s83, s84, s85, s86, s87, s88, s89, s90, s91, s92, s93, s94, s95, s96, s97, s98, s99\] -> (s0 \* 4428 + s1 \* 394 - s2 \* 5572 - s3 \* 9275 + s4 \* 4108 + s5 \* 6656 + s6 \* 7912 - s7 \* 1953 - s8 \* 7438 - s9 \* 7540 - s10 \* 131 - s11 \* 4508 + s12 \* 1560 - s13 \* 5586 + s14 \* 8159 + s15 \* 932 - s16 \* 8506 - s17 \* 3325 - s18 \* 5040 + s19 \* 7930 - s20 \* 3091 + s21 \* 2389 + s22 \* 9877 + s23 \* 1941 - s24 \* 8175 - s25 \* 9956 + s26 \* 6537 + s27 \* 8439 - s28 \* 262 - s29 \* 8363 - s30 \* 34 + s31 \* 5919 + s32 \* 7510 - s33 \* 2022 + s34 \* 9986 - s35 \* 2417 + s36 \* 892 + s37 \* 6307 - s38 \* 8347 + s39 \* 3130 + s40 \* 6385 + s41 \* 2693 - s42 \* 4571 - s43 \* 3279 - s44 \* 7035 + s45 \* 5372 - s46 \* 3948 - s47 \* 5548 - s48 \* 2615 - s49 \* 1547 + s50 \* 8 - s51 \* 4483 - s52 \* 9041 + s53 \* 2074 + s54 \* 6123 + s55 \* 9648 - s56 \* 4958 - s57 \* 8982 + s58 \* 8436 - s59 \* 7755 - s60 \* 3659 + s61 \* 3272 + s62 \* 6137 + s63 \* 1058 + s64 \* 3285 - s65 \* 985 + s66 \* 1658 + s67 \* 8626 - s68 \* 7975 - s69 \* 9610 - s70 \* 8678 - s71 \* 768 - s72 \* 2846 - s73 \* 5229 + s74 \* 1065 + s75 \* 6757 + s76 \* 8854 - s77 \* 7809 - s78 \* 2659 - s79 \* 592 - s80 \* 5537 - s81 \* 7616 + s82 \* 2033 - s83 \* 5121 - s84 \* 9005 - s85 \* 8493 + s86 \* 4449 - s87 \* 5269 - s88 \* 8447 + s89 \* 8878 + s90 \* 1967 + s91 \* 1938 + s92 \* 2483 - s93 \* 6314 + s94 \* 7379 + s95 \* 6090 + s96 \* 1264 - s97 \* 5371 + s98 \* 1766 - s99 \* 2218)>\]} Is this just not meant to handle larger equations?
lipracer commented 1 month ago

https://github.com/llvm/llvm-project/blame/main/mlir/lib/IR/AffineExpr.cpp#L1561 It's just check fold result if there has posion expression (like divide by zero), I construct below test cases it's work well.Can you provide me with some additional information? For example, the specific numerical values of s0 s1 s2... mlir-opt -test-constant-fold -split-input-file a.mlir

#map0 = affine_map<(d0)[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, s32, s33,
s34, s35, s36, s37, s38, s39, s40, s41, s42, s43, s44, s45, s46, s47, s48, s49, s50, s51, s52, s53, s54, s55, s56, s57, s58, s59, s60, s61, s62, s63, s64, s65, s66, s67, s68, s69, s70,
s71, s72, s73, s74, s75, s76, s77, s78, s79, s80, s81, s82, s83, s84, s85, s86, s87, s88, s89, s90, s91, s92, s93, s94, s95, s96, s97, s98, s99] -> (s0 * 4428 + s1 * 394 - s2 * 5572 -
s3 * 9275 + s4 * 4108 + s5 * 6656 + s6 * 7912 - s7 * 1953 - s8 * 7438 - s9 * 7540 - s10 * 131 - s11 * 4508 + s12 * 1560 - s13 * 5586 + s14 * 8159 + s15 * 932 - s16 * 8506 - s17 * 3325 -
s18 * 5040 + s19 * 7930 - s20 * 3091 + s21 * 2389 + s22 * 9877 + s23 * 1941 - s24 * 8175 - s25 * 9956 + s26 * 6537 + s27 * 8439 - s28 * 262 - s29 * 8363 - s30 * 34 + s31 * 5919 + s32 *
7510 - s33 * 2022 + s34 * 9986 - s35 * 2417 + s36 * 892 + s37 * 6307 - s38 * 8347 + s39 * 3130 + s40 * 6385 + s41 * 2693 - s42 * 4571 - s43 * 3279 - s44 * 7035 + s45 * 5372 - s46 * 3948 -
s47 * 5548 - s48 * 2615 - s49 * 1547 + s50 * 8 - s51 * 4483 - s52 * 9041 + s53 * 2074 + s54 * 6123 + s55 * 9648 - s56 * 4958 - s57 * 8982 + s58 * 8436 - s59 * 7755 - s60 * 3659 + s61 *
3272 + s62 * 6137 + s63 * 1058 + s64 * 3285 - s65 * 985 + s66 * 1658 + s67 * 8626 - s68 * 7975 - s69 * 9610 - s70 * 8678 - s71 * 768 - s72 * 2846 - s73 * 5229 + s74 * 1065 + s75 * 6757 +
s76 * 8854 - s77 * 7809 - s78 * 2659 - s79 * 592 - s80 * 5537 - s81 * 7616 + s82 * 2033 - s83 * 5121 - s84 * 9005 - s85 * 8493 + s86 * 4449 - s87 * 5269 - s88 * 8447 + s89 * 8878 + s90 *
1967 + s91 * 1938 + s92 * 2483 - s93 * 6314 + s94 * 7379 + s95 * 6090 + s96 * 1264 - s97 * 5371 + s98 * 1766 - s99 * 2218)>
func.func @affine_apply(%arg0 : index, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : index, %arg6 : index, %arg7 : index, %arg8 : index, %arg9 : index, %arg10 : index, %arg11 : index, %arg12 : index, %arg13 : index, %arg14 : index, %arg15 : index, %arg16 : index, %arg17 : index, %arg18 : index, %arg19 : index, %arg20 : index, %arg21 : index, %arg22 : index, %arg23 : index, %arg24 : index, %arg25 : index, %arg26 : index, %arg27 : index, %arg28 : index, %arg29 : index, %arg30 : index, %arg31 : index, %arg32 : index, %arg33 : index, %arg34 : index, %arg35 : index, %arg36 : index, %arg37 : index, %arg38 : index, %arg39 : index, %arg40 : index, %arg41 : index, %arg42 : index, %arg43 : index, %arg44 : index, %arg45 : index, %arg46 : index, %arg47 : index, %arg48 : index, %arg49 : index, %arg50 : index, %arg51 : index, %arg52 : index, %arg53 : index, %arg54 : index, %arg55 : index, %arg56 : index, %arg57 : index, %arg58 : index, %arg59 : index, %arg60 : index, %arg61 : index, %arg62 : index, %arg63 : index, %arg64 : index, %arg65 : index, %arg66 : index, %arg67 : index, %arg68 : index, %arg69 : index, %arg70 : index, %arg71 : index, %arg72 : index, %arg73 : index, %arg74 : index, %arg75 : index, %arg76 : index, %arg77 : index, %arg78 : index, %arg79 : index, %arg80 : index, %arg81 : index, %arg82 : index, %arg83 : index, %arg84 : index, %arg85 : index, %arg86 : index, %arg87 : index, %arg88 : index, %arg89 : index, %arg90 : index, %arg91 : index, %arg92 : index, %arg93 : index, %arg94 : index, %arg95 : index, %arg96 : index, %arg97 : index, %arg98 : index, %arg99 : index) -> (index) {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  %c2 = arith.constant 2 : index
  %c3 = arith.constant 3 : index
  %c4 = arith.constant 4 : index
  %c5 = arith.constant 5 : index
  %c6 = arith.constant 6 : index
  %c7 = arith.constant 7 : index
  %c8 = arith.constant 8 : index
  %c9 = arith.constant 9 : index
  %c10 = arith.constant 10 : index
  %c11 = arith.constant 11 : index
  %c12 = arith.constant 12 : index
  %c13 = arith.constant 13 : index
  %c14 = arith.constant 14 : index
  %c15 = arith.constant 15 : index
  %c16 = arith.constant 16 : index
  %c17 = arith.constant 17 : index
  %c18 = arith.constant 18 : index
  %c19 = arith.constant 19 : index
  %c20 = arith.constant 20 : index
  %c21 = arith.constant 21 : index
  %c22 = arith.constant 22 : index
  %c23 = arith.constant 23 : index
  %c24 = arith.constant 24 : index
  %c25 = arith.constant 25 : index
  %c26 = arith.constant 26 : index
  %c27 = arith.constant 27 : index
  %c28 = arith.constant 28 : index
  %c29 = arith.constant 29 : index
  %c30 = arith.constant 30 : index
  %c31 = arith.constant 31 : index
  %c32 = arith.constant 32 : index
  %c33 = arith.constant 33 : index
  %c34 = arith.constant 34 : index
  %c35 = arith.constant 35 : index
  %c36 = arith.constant 36 : index
  %c37 = arith.constant 37 : index
  %c38 = arith.constant 38 : index
  %c39 = arith.constant 39 : index
  %c40 = arith.constant 40 : index
  %c41 = arith.constant 41 : index
  %c42 = arith.constant 42 : index
  %c43 = arith.constant 43 : index
  %c44 = arith.constant 44 : index
  %c45 = arith.constant 45 : index
  %c46 = arith.constant 46 : index
  %c47 = arith.constant 47 : index
  %c48 = arith.constant 48 : index
  %c49 = arith.constant 49 : index
  %c50 = arith.constant 50 : index
  %c51 = arith.constant 51 : index
  %c52 = arith.constant 52 : index
  %c53 = arith.constant 53 : index
  %c54 = arith.constant 54 : index
  %c55 = arith.constant 55 : index
  %c56 = arith.constant 56 : index
  %c57 = arith.constant 57 : index
  %c58 = arith.constant 58 : index
  %c59 = arith.constant 59 : index
  %c60 = arith.constant 60 : index
  %c61 = arith.constant 61 : index
  %c62 = arith.constant 62 : index
  %c63 = arith.constant 63 : index
  %c64 = arith.constant 64 : index
  %c65 = arith.constant 65 : index
  %c66 = arith.constant 66 : index
  %c67 = arith.constant 67 : index
  %c68 = arith.constant 68 : index
  %c69 = arith.constant 69 : index
  %c70 = arith.constant 70 : index
  %c71 = arith.constant 71 : index
  %c72 = arith.constant 72 : index
  %c73 = arith.constant 73 : index
  %c74 = arith.constant 74 : index
  %c75 = arith.constant 75 : index
  %c76 = arith.constant 76 : index
  %c77 = arith.constant 77 : index
  %c78 = arith.constant 78 : index
  %c79 = arith.constant 79 : index
  %c80 = arith.constant 80 : index
  %c81 = arith.constant 81 : index
  %c82 = arith.constant 82 : index
  %c83 = arith.constant 83 : index
  %c84 = arith.constant 84 : index
  %c85 = arith.constant 85 : index
  %c86 = arith.constant 86 : index
  %c87 = arith.constant 87 : index
  %c88 = arith.constant 88 : index
  %c89 = arith.constant 89 : index
  %c90 = arith.constant 90 : index
  %c91 = arith.constant 91 : index
  %c92 = arith.constant 92 : index
  %c93 = arith.constant 93 : index
  %c94 = arith.constant 94 : index
  %c95 = arith.constant 95 : index
  %c96 = arith.constant 96 : index
  %c97 = arith.constant 97 : index
  %c98 = arith.constant 98 : index
  %c99 = arith.constant 99 : index
  %x0 = affine.apply #map0(%c1)[%c0, %c1, %c2, %c3, %c4, %c5, %c6, %c7, %c8, %c9, %c10, %c11, %c12, %c13, %c14, %c15, %c16, %c17, %c18, %c19, %c20, %c21, %c22, %c23, %c24, %c25, %c26, %c27, %c28, %c29, %c30, %c31, %c32, %c33, %c34, %c35, %c36, %c37, %c38, %c39, %c40, %c41, %c42, %c43, %c44, %c45, %c46, %c47, %c48, %c49, %c50, %c51, %c52, %c53, %c54, %c55, %c56, %c57, %c58, %c59, %c60, %c61, %c62, %c63, %c64, %c65, %c66, %c67, %c68, %c69, %c70, %c71, %c72, %c73, %c74, %c75, %c76, %c77, %c78, %c79, %c80, %c81, %c82, %c83, %c84, %c85, %c86, %c87, %c88, %c89, %c90, %c91, %c92, %c93, %c94, %c95, %c96, %c97, %c98, %c99]
  %x1 = affine.apply #map0(%c1)[%arg0, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12, %arg13, %arg14, %arg15, %arg16, %arg17, %arg18, %arg19, %arg20, %arg21, %arg22, %arg23, %arg24, %arg25, %arg26, %arg27, %arg28, %arg29, %arg30, %arg31, %arg32, %arg33, %arg34, %arg35, %arg36, %arg37, %arg38, %arg39, %arg40, %arg41, %arg42, %arg43, %arg44, %arg45, %arg46, %arg47, %arg48, %arg49, %arg50, %arg51, %arg52, %arg53, %arg54, %arg55, %arg56, %arg57, %arg58, %arg59, %arg60, %arg61, %arg62, %arg63, %arg64, %arg65, %arg66, %arg67, %arg68, %arg69, %arg70, %arg71, %arg72, %arg73, %arg74, %arg75, %arg76, %arg77, %arg78, %arg79, %arg80, %arg81, %arg82, %arg83, %arg84, %arg85, %arg86, %arg87, %arg88, %arg89, %arg90, %arg91, %arg92, %arg93, %arg94, %arg95, %arg96, %arg97, %arg98, %arg99]
  %x2 = arith.addi %x0, %x1 : index
  return %x2 : index
}