This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Fold ShuffleOp if result is identical to one of source vectors.
ClosedPublic

Authored by jacquesguan on Mar 30 2022, 1:01 AM.

Details

Summary

For example, we could do the following eliminations:

fold vector.shuffle V1, V2, [0, 1, 2, 3] : <4xi32>, <2xi32> -> V1
fold vector.shuffle V1, V2, [4, 5] : <4xi32>, <2xi32> -> V2

Diff Detail

Event Timeline

jacquesguan created this revision.Mar 30 2022, 1:01 AM
Herald added a project: Restricted Project. · View Herald Transcript
jacquesguan requested review of this revision.Mar 30 2022, 1:01 AM

remove some irrelevant change.

nicolasvasilache accepted this revision.Mar 30 2022, 1:14 AM

Thanks!

mlir/lib/Dialect/Vector/IR/VectorOps.cpp
1773

Note: we use snakeCase for function and variable names in he MLIR coding style:

static bool isStepIndexArray(ArrayAttr idxArr, int64_t begin, int64_t width) {...}
1774
int64_t expected = begin;
return idxArr.size() == width && 
   llvm::all_of(idxArr.getAsValueRange<IntegerAttr>(), 
                      [&expected](IntegerAttr attr){ return attr.getZExtValue() == expected++; });
This revision is now accepted and ready to land.Mar 30 2022, 1:14 AM

Address comment.

mlir/lib/Dialect/Vector/IR/VectorOps.cpp
1773

Done, thanks a lot.

1774

Done.

Hi @jacquesguan ,

This change has caused a build error when building with clang:

/usr/bin/clang++ -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=0 -DMLIR_ROCM_CONVERSIONS_ENABLED=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/mnt/vss/_work/1/b/llvm/Release/tools/mlir/lib/Dialect/Vector/IR -I/mnt/vss/_work/1/llvm-project/mlir/lib/Dialect/Vector/IR -I/mnt/vss/_work/1/b/llvm/Release/include -I/mnt/vss/_work/1/llvm-project/llvm/include -I/mnt/vss/_work/1/llvm-project/mlir/include -I/mnt/vss/_work/1/b/llvm/Release/tools/mlir/include -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=mismatched-tags -Werror=global-constructors -O3 -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT tools/mlir/lib/Dialect/Vector/IR/CMakeFiles/obj.MLIRVector.dir/VectorOps.cpp.o -MF tools/mlir/lib/Dialect/Vector/IR/CMakeFiles/obj.MLIRVector.dir/VectorOps.cpp.o.d -o tools/mlir/lib/Dialect/Vector/IR/CMakeFiles/obj.MLIRVector.dir/VectorOps.cpp.o -c /mnt/vss/_work/1/llvm-project/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
/mnt/vss/_work/1/llvm-project/mlir/lib/Dialect/Vector/IR/VectorOps.cpp:1793:24: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int64_t' (aka 'long') [-Werror,-Wsign-compare]
  return idxArr.size() == width &&
         ~~~~~~~~~~~~~ ^  ~~~~~
/mnt/vss/_work/1/llvm-project/mlir/lib/Dialect/Vector/IR/VectorOps.cpp:1796:52: error: comparison of integers of different signs: 'uint64_t' (aka 'unsigned long') and 'int64_t' (aka 'long') [-Werror,-Wsign-compare]
                        return attr.getZExtValue() == expected++;
                               ~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~

Thanks,

Henry