llvm / llvm-project

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

MLIR: MLIR does not support all flags from LLVM #99353

Open AtticusKuhn opened 1 month ago

AtticusKuhn commented 1 month ago

Suprisingly, I think that MLIR doesn't support all the flags from LLVM. Here is one example.

Consider the following LLVM file:

define i8 @negation_of_increment_via_or_disjoint(i8 %x, i8 %y) {
  %t1 = or disjoint i8 %y, 1
  %t2 = sub i8 %x, %t1
  ret i8 %t2
}

Then, I run mlir-translate -import-llvm disjoint.ll and I get

module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<64> :
vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<[32, 64]> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">>} {
  llvm.func @negation_of_increment_via_or_disjoint(%arg0: i8, %arg1: i8) -> i8 {
    %0 = llvm.mlir.constant(1 : i8) : i8
    %1 = llvm.or %arg1, %0  : i8
    %2 = llvm.sub %arg0, %1  : i8
    llvm.return %2 : i8
  }
}

So it seems that the disjoint flag has entirely disappeared from MLIR. I think this is a bug in MLIR.

dtcxzyw commented 1 month ago

There are some poison-generating flags that are not yet supported:

llvmbot commented 1 month ago

@llvm/issue-subscribers-mlir-llvm

Author: Atticus Kuhn (AtticusKuhn)

Suprisingly, I think that MLIR doesn't support all the flags from LLVM. Here is one example. Consider the following LLVM file: ```llvm define i8 @negation_of_increment_via_or_disjoint(i8 %x, i8 %y) { %t1 = or disjoint i8 %y, 1 %t2 = sub i8 %x, %t1 ret i8 %t2 } ``` Then, I run `mlir-translate -import-llvm disjoint.ll` and I get ```mlir module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<[32, 64]> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">>} { llvm.func @negation_of_increment_via_or_disjoint(%arg0: i8, %arg1: i8) -> i8 { %0 = llvm.mlir.constant(1 : i8) : i8 %1 = llvm.or %arg1, %0 : i8 %2 = llvm.sub %arg0, %1 : i8 llvm.return %2 : i8 } } ``` So it seems that the `disjoint` flag has entirely disappeared from MLIR. I think this is a bug in MLIR.
AtticusKuhn commented 1 month ago

There are some poison-generating flags that are not yet supported:

  • disjoint: or
  • exact: lshr/ashr/sdiv/udiv
  • nsw/nusw: getelementptr
  • nneg: zext/uitofp
  • nsw/nuw: trunc

Thanks you for your response. Are there any plans to support these features in the future? Otherwise, is there any way to get mlir-translate to throw a warning when it encounters an unsupported feature?

dtcxzyw commented 1 month ago

Are there any plans to support these features in the future?

I am not MLIR maintainer. IMO arith dialect should support these flags first.

Otherwise, is there any way to get mlir-translate to throw a warning when it encounters an unsupported feature?

You can use Instruction::hasPoisonGeneratingFlags.