Skip to content

[SelectionDAG] Simplify classof of MemSDNode and MemIntrinsicSDNode (NFC) #115720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

s-barannikov
Copy link
Contributor

SDNodeBits.IsMemIntrinsic is set if and only if the node is an instance of MemIntrinsicSDNode. Thus, to check if a node is an instance of MemIntrinsicSDNode we only need to check this bit.

…NFC)

`SDNodeBits.IsMemIntrinsic` is set if and only if the node is an
instance of `MemIntrinsicSDNode`. Thus, to check if a node is an
instance of `MemIntrinsicSDNode` we only need to check this bit.
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Nov 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: Sergei Barannikov (s-barannikov)

Changes

SDNodeBits.IsMemIntrinsic is set if and only if the node is an instance of MemIntrinsicSDNode. Thus, to check if a node is an instance of MemIntrinsicSDNode we only need to check this bit.


Full diff: https://github.com/llvm/llvm-project/pull/115720.diff

1 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-14)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 739ce05e947346..677b59e0c8fbeb 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -708,15 +708,7 @@ END_TWO_BYTE_PACK()
   bool isUndef() const { return NodeType == ISD::UNDEF; }
 
   /// Test if this node is a memory intrinsic (with valid pointer information).
-  /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
-  /// non-memory intrinsics (with chains) that are not really instances of
-  /// MemSDNode. For such nodes, we need some extra state to determine the
-  /// proper classof relationship.
-  bool isMemIntrinsic() const {
-    return (NodeType == ISD::INTRINSIC_W_CHAIN ||
-            NodeType == ISD::INTRINSIC_VOID) &&
-           SDNodeBits.IsMemIntrinsic;
-  }
+  bool isMemIntrinsic() const { return SDNodeBits.IsMemIntrinsic; }
 
   /// Test if this node is a strict floating point pseudo-op.
   bool isStrictFPOpcode() {
@@ -1464,7 +1456,6 @@ class MemSDNode : public SDNode {
     switch (N->getOpcode()) {
     case ISD::LOAD:
     case ISD::STORE:
-    case ISD::PREFETCH:
     case ISD::ATOMIC_CMP_SWAP:
     case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS:
     case ISD::ATOMIC_SWAP:
@@ -1504,7 +1495,7 @@ class MemSDNode : public SDNode {
     case ISD::EXPERIMENTAL_VECTOR_HISTOGRAM:
       return true;
     default:
-      return N->isMemIntrinsic() || N->isTargetMemoryOpcode();
+      return N->isMemIntrinsic();
     }
   }
 };
@@ -1596,9 +1587,7 @@ class MemIntrinsicSDNode : public MemSDNode {
   static bool classof(const SDNode *N) {
     // We lower some target intrinsics to their target opcode
     // early a node with a target opcode can be of this class
-    return N->isMemIntrinsic()             ||
-           N->getOpcode() == ISD::PREFETCH ||
-           N->isTargetMemoryOpcode();
+    return N->isMemIntrinsic();
   }
 };
 

NodeType == ISD::INTRINSIC_VOID) &&
SDNodeBits.IsMemIntrinsic;
}
bool isMemIntrinsic() const { return SDNodeBits.IsMemIntrinsic; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this SDNodeBits part of a union? Isn't the opcode check to make sure that part of the union is active?

Copy link
Contributor Author

@s-barannikov s-barannikov Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structs other than SDNodeBitfields have first NumSDNodeBits bits reserved.
That is, IsMemIntrinsic is shared between all structs in the union.

I think the opcode check is a historical artifact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this opcode check doesn't really tell us which union member is active because INTRINSIC_W_CHAIN / INTRINSIC_VOID can either be an ordinary SDNode or MemIntrinsicSDNode. If I read the removed comment correctly, this bit was introduced to disambiguate these cases, but introducing it also made the opcode check redundant.

Assuming there is no (pre-existing) undefined behavior, just checking the bit is more robust as the method will now return false for ordinary SDNodes erroneously created with isTargetMemoryOpcode opcodes.

Copy link
Collaborator

@topperc topperc Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

Assuming there is no (pre-existing) undefined behavior, just checking the bit is more robust as the method will now return false for ordinary SDNodes erroneously created with isTargetMemoryOpcode opcodes.

I think that would be considered a bug to not use SDMemIntrinsicSDNode for anything that isTargetMemoryOpcode()

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@s-barannikov s-barannikov merged commit 3aa24ea into llvm:main Nov 12, 2024
10 checks passed
@s-barannikov s-barannikov deleted the simplify-is-mem-intrinsic branch November 12, 2024 06:36
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 12, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian running on libc-x86_64-debian while building llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/43/builds/10080

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcFStatTest.NonExistentFile (4 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[922/984] Running unit test libc.test.src.sys.statvfs.linux.statvfs_test
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcSysStatvfsTest.StatvfsBasic
[       OK ] LlvmLibcSysStatvfsTest.StatvfsBasic (15 us)
[ RUN      ] LlvmLibcSysStatvfsTest.StatvfsInvalidPath
[       OK ] LlvmLibcSysStatvfsTest.StatvfsInvalidPath (136 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[923/984] Running unit test libc.test.src.sys.statvfs.linux.fstatvfs_test
FAILED: projects/libc/test/src/sys/statvfs/linux/CMakeFiles/libc.test.src.sys.statvfs.linux.fstatvfs_test /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/sys/statvfs/linux/CMakeFiles/libc.test.src.sys.statvfs.linux.fstatvfs_test 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/sys/statvfs/linux && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/test/src/sys/statvfs/linux/libc.test.src.sys.statvfs.linux.fstatvfs_test.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcSysFStatvfsTest.FStatvfsBasic
[       OK ] LlvmLibcSysFStatvfsTest.FStatvfsBasic (20 us)
[ RUN      ] LlvmLibcSysFStatvfsTest.FStatvfsInvalidPath
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp:40: FAILURE
Failed to match LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU) against Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "File exists".
[  FAILED  ] LlvmLibcSysFStatvfsTest.FStatvfsInvalidPath
Ran 2 tests.  PASS: 1  FAIL: 1
[924/984] Running unit test libc.test.src.sys.utsname.uname_test
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcUnameTest.GetMachineName
[       OK ] LlvmLibcUnameTest.GetMachineName (6 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[925/984] Running unit test libc.test.src.sys.wait.waitpid_test
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcWaitPidTest.NoHangTest
[       OK ] LlvmLibcWaitPidTest.NoHangTest (4 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[926/984] Running unit test libc.test.src.sys.wait.wait4_test
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcwait4Test.NoHangTest
[       OK ] LlvmLibcwait4Test.NoHangTest (5 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[927/984] Running unit test libc.test.src.string.memmove_opt_host_test.__unit__
[==========] Running 7 tests from 1 test suite.
[ RUN      ] LlvmLibcMemmoveTest.MoveZeroByte
[       OK ] LlvmLibcMemmoveTest.MoveZeroByte (3 us)
[ RUN      ] LlvmLibcMemmoveTest.DstAndSrcPointToSameAddress
[       OK ] LlvmLibcMemmoveTest.DstAndSrcPointToSameAddress (1 us)
[ RUN      ] LlvmLibcMemmoveTest.DstStartsBeforeSrc
[       OK ] LlvmLibcMemmoveTest.DstStartsBeforeSrc (1 us)
[ RUN      ] LlvmLibcMemmoveTest.DstStartsAfterSrc
[       OK ] LlvmLibcMemmoveTest.DstStartsAfterSrc (2 us)
[ RUN      ] LlvmLibcMemmoveTest.SrcFollowDst
[       OK ] LlvmLibcMemmoveTest.SrcFollowDst (1 us)

Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
…NFC) (llvm#115720)

`SDNodeBits.IsMemIntrinsic` is set if and only if the node is an
instance of `MemIntrinsicSDNode`. Thus, to check if a node is an
instance of `MemIntrinsicSDNode` we only need to check this bit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants