This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][NFC][1/4]Refactor 'isBitfieldPositioningOp' so that DAG nodes with different Opcode are handled with separate helper functions
ClosedPublic

Authored by mingmingl on Oct 12 2022, 7:15 PM.

Details

Summary

The rationale to use different helper functions for DAG nodes with different Opcode is to specialize the optimization.

isBitfieldExtractOp shows how specialization based on Opcode could help.

This paves the way for enhancement in D135844: [AArch64][2/4]Regard (shl val, N) as a potential bit-field-positioning op regardless of the number of uses.

Diff Detail

Event Timeline

mingmingl created this revision.Oct 12 2022, 7:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 7:15 PM
mingmingl requested review of this revision.Oct 12 2022, 7:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 7:15 PM
mingmingl retitled this revision from [AArch64][NFC]Refactor 'isBitfieldPositioningOp' so Op with different Opcode is handled with a separaparate helper function (which issimilar to 'isBitfieldExtractOp'). This paves the way for enhancement to [AArch64][NFC]Refactor 'isBitfieldPositioningOp' so that DAG nodes with different Opcode are handled with separate helper functions.Oct 13 2022, 12:00 AM
mingmingl edited the summary of this revision. (Show Details)
mingmingl added a reviewer: dmgreen.
mingmingl retitled this revision from [AArch64][NFC]Refactor 'isBitfieldPositioningOp' so that DAG nodes with different Opcode are handled with separate helper functions to [AArch64][NFC][1/4]Refactor 'isBitfieldPositioningOp' so that DAG nodes with different Opcode are handled with separate helper functions.

You can link patches together with the "Edit Related Revision", allowing them to be stacked together to show they are dependant on one another.

These do seems to end up quite different, even if some of the differences here could be reduced.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2522

If this only has a single use it may be better to inline, so there is only a single variable pointing to Op.

2579–2581

This can go at the start of the function, and use Op.getValueType().

2589

This needn't set Src.

2649–2650

Op.getOpcode()

mingmingl marked 4 inline comments as done.

Address comments

  1. Call forwarding methods (getOperand, hasOneUse, etc) of class SDValue as much as possible.
  2. To minimize displayed diff, reorder functions (declare helpers and define them after 'isBitfieldPositioningOp'); otherwise, newly added helper for AND will be diff'ed against the original 'isBitfieldPositioningOp'

You can link patches together with the "Edit Related Revision", allowing them to be stacked together to show they are dependant on one another.

These do seems to end up quite different, even if some of the differences here could be reduced.

Done. Thanks for pointing this out!

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2522

Done by calling the forwarding method of SDValue class as much as possible (here and below)

dmgreen accepted this revision.Oct 16 2022, 11:57 PM

Thanks. I agree that with the other patches this sounds like a sensible thing to split out. LGTM

This revision is now accepted and ready to land.Oct 16 2022, 11:57 PM

Thanks! Going to commit.

This patch seems to be causing build failures when a build is configured with -Werror due to the warnings (e.g. https://lab.llvm.org/buildbot/#/builders/57/builds/22957). May I get your help @mingmingl for some advices/fixes to get the build going? Thank you!

/home/buildbots/clang.11.0.0/bin/clang++ --gcc-toolchain=/opt/rh/devtoolset-7/root/usr  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Target/AArch64 -I/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/lib/Target/AArch64 -Iinclude -I/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/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 -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fPIC    -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64ISelDAGToDAG.cpp.o -MF lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64ISelDAGToDAG.cpp.o.d -o lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64ISelDAGToDAG.cpp.o -c /home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp:2596:14: error: comparison of integers of different signs: 'uint64_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
  if (ShlImm != DstLSB && !BiggerPattern)
      ~~~~~~ ^  ~~~~~~
/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp:2661:14: error: comparison of integers of different signs: 'int' and 'uint64_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
  if (DstLSB != ShlImm && !BiggerPattern)
      ~~~~~~ ^  ~~~~~~
2 errors generated.

Ahhh i missed the message completely (and saw the comment when looked back at patches).. Thanks for the speedy fix @MaskRay !