Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 7, 2025

This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.

Copy link
Contributor Author

arsenm commented Apr 7, 2025

@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp (+16-13)
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 41bf202230e22..e25ec6c3b2a58 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -111,20 +111,23 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
 
   Value *Ret = nullptr;
 
-  // Check to see if there is already a cast!
-  for (User *U : V->users()) {
-    if (U->getType() != Ty)
-      continue;
-    CastInst *CI = dyn_cast<CastInst>(U);
-    if (!CI || CI->getOpcode() != Op)
-      continue;
+  if (!isa<Constant>(V)) {
+    // Check to see if there is already a cast!
+    for (User *U : V->users()) {
+      if (U->getType() != Ty)
+        continue;
+      CastInst *CI = dyn_cast<CastInst>(U);
+      if (!CI || CI->getOpcode() != Op)
+        continue;
 
-    // Found a suitable cast that is at IP or comes before IP. Use it. Note that
-    // the cast must also properly dominate the Builder's insertion point.
-    if (IP->getParent() == CI->getParent() && &*BIP != CI &&
-        (&*IP == CI || CI->comesBefore(&*IP))) {
-      Ret = CI;
-      break;
+      // Found a suitable cast that is at IP or comes before IP. Use it. Note
+      // that the cast must also properly dominate the Builder's insertion
+      // point.
+      if (IP->getParent() == CI->getParent() && &*BIP != CI &&
+          (&*IP == CI || CI->comesBefore(&*IP))) {
+        Ret = CI;
+        break;
+      }
     }
   }
 

@arsenm arsenm marked this pull request as ready for review April 7, 2025 17:01
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

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@arsenm arsenm force-pushed the users/arsenm/licm/stop-using-constantdata-use-lists branch from 05c26c5 to 7954b84 Compare April 8, 2025 00:26
@arsenm arsenm force-pushed the users/arsenm/scev-expander/do-not-look-at-uses-of-constants branch from f543f05 to aedd9ec Compare April 8, 2025 00:27
@arsenm arsenm force-pushed the users/arsenm/licm/stop-using-constantdata-use-lists branch from 7954b84 to fa88dda Compare April 12, 2025 09:25
@arsenm arsenm force-pushed the users/arsenm/scev-expander/do-not-look-at-uses-of-constants branch from aedd9ec to 30c317d Compare April 12, 2025 09:25
This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.
@arsenm arsenm force-pushed the users/arsenm/licm/stop-using-constantdata-use-lists branch from fa88dda to a0cee0a Compare April 13, 2025 10:16
@arsenm arsenm force-pushed the users/arsenm/scev-expander/do-not-look-at-uses-of-constants branch from 30c317d to 36377c3 Compare April 13, 2025 10:16
arsenm added a commit that referenced this pull request Apr 13, 2025
This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.
@arsenm
Copy link
Contributor Author

arsenm commented Apr 13, 2025

30ae47e

@arsenm arsenm closed this Apr 13, 2025
@arsenm arsenm deleted the users/arsenm/scev-expander/do-not-look-at-uses-of-constants branch April 25, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants