Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Oct 31, 2025

There do not appear to be any cases where this is used.
This does introduce an odd asyemmtry where use_empty is not
equivalent to hasNUses(0).

@arsenm arsenm marked this pull request as ready for review October 31, 2025 22:00
Copy link
Contributor Author

arsenm commented Oct 31, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/IR/Value.cpp (-8)
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index b775cbb0c7920..95d61a987f6c1 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -148,18 +148,10 @@ void Value::destroyValueName() {
 }
 
 bool Value::hasNUses(unsigned N) const {
-  if (!UseList)
-    return N == 0;
-
-  // TODO: Disallow for ConstantData and remove !UseList check?
   return hasNItems(use_begin(), use_end(), N);
 }
 
 bool Value::hasNUsesOrMore(unsigned N) const {
-  // TODO: Disallow for ConstantData and remove !UseList check?
-  if (!UseList)
-    return N == 0;
-
   return hasNItemsOrMore(use_begin(), use_end(), N);
 }
 

@arsenm arsenm force-pushed the users/arsenm/ir/value-remove-UseList-null-checks branch from 428c6d6 to ffa6cac Compare October 31, 2025 22:31
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

@arsenm arsenm enabled auto-merge (squash) November 4, 2025 02:52
arsenm and others added 3 commits November 3, 2025 20:31
There do not appear to be any cases where this is used.
This does introduce an odd asyemmtry where use_empty is not
equivalent to hasNUses(0).
Co-authored-by: Nikita Popov <npopov@redhat.com>
@arsenm arsenm force-pushed the users/arsenm/ir/value-remove-UseList-null-checks branch from 96e04af to f83ef56 Compare November 4, 2025 04:33
@arsenm arsenm merged commit 93e860e into main Nov 4, 2025
10 checks passed
@arsenm arsenm deleted the users/arsenm/ir/value-remove-UseList-null-checks branch November 4, 2025 05:09
@danilaml
Copy link
Collaborator

danilaml commented Nov 4, 2025

Hm, got a llvm::Value::const_use_iterator llvm::Value::materialized_use_begin() const: Assertion hasUseList()' failed.` assert on one of downstream test where

    for (Value *Op : Item->operands())
      if (Op->hasNUses(1))

Was called and I believe Op became Constant after instcombine pass. Didn't have a chance to do a closer check though so it might be something on our end.

@arsenm
Copy link
Contributor Author

arsenm commented Nov 4, 2025

Was called and I believe Op became Constant after instcombine pass. Didn't have a chance to do a closer check though so it might be something on our end.

You shouldn't rely on the use lists of ConstantData. We still tolerate use_empty checks on them, mostly because there's just too much code to fix at a time

@danilaml
Copy link
Collaborator

danilaml commented Nov 4, 2025

@arsenm it wasn't relying on uselists of a constant data. It was relying on hasNUses call on Value (just instruction operands). In this case it was trivial to add a dyn_cast check but currently hasNUses feels footgun-y. All "unqualified" (i.e. on plain Value) calls are now suspect.

Also, hasOneUse still has the check, if you want to go all the way.

@arsenm
Copy link
Contributor Author

arsenm commented Nov 5, 2025

@arsenm it wasn't relying on uselists of a constant data. It was relying on hasNUses call on Value (just instruction operands). In this case it was trivial to add a dyn_cast check but currently hasNUses feels footgun-y. All "unqualified" (i.e. on plain Value) calls are now suspect.

Also, hasOneUse still has the check, if you want to go all the way.

That's a pain. Probably should revert this then

arsenm added a commit that referenced this pull request Nov 5, 2025
This reverts commit 93e860e.

hasOneUse still has the null check, and it seems bad to be logically
inconsistent across multiple of these predicate functions.
arsenm added a commit that referenced this pull request Nov 5, 2025
…#166500)

This reverts commit 93e860e.

hasOneUse still has the null check, and it seems bad to be logically
inconsistent across multiple of these predicate functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants