Skip to content

[CodeGen][SDAG] Skip preferred extend at O0 #92643

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
May 19, 2024

Conversation

aengelke
Copy link
Contributor

This should be a pure optimization to avoid redundant extensions, but iterating over all users is expensive, so don't do this at -O0.

Note: I'm unsure whether this is required for something at O0, but it appears to be fine.

This is a pure optimization to avoid redundant extensions, but iterating
over all users is expensive, so don't do this at -O0.
@aengelke aengelke requested review from RKSimon and topperc May 18, 2024 09:44
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label May 18, 2024
@llvmbot
Copy link
Member

llvmbot commented May 18, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: None (aengelke)

Changes

This should be a pure optimization to avoid redundant extensions, but iterating over all users is expensive, so don't do this at -O0.

Note: I'm unsure whether this is required for something at O0, but it appears to be fine.


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

2 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (+4-2)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 979ef8033eb5e..ed6962685f7b0 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -469,6 +469,7 @@ class SelectionDAG {
   MachineFunction &getMachineFunction() const { return *MF; }
   const Pass *getPass() const { return SDAGISelPass; }
 
+  CodeGenOptLevel getOptLevel() const { return OptLevel; }
   const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
   const TargetMachine &getTarget() const { return TM; }
   const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }
diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 8fb6b11b8805c..35f840201e4ba 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -222,8 +222,10 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
         if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I)))
           InitializeRegForValue(&I);
 
-      // Decide the preferred extend type for a value.
-      PreferredExtendType[&I] = getPreferredExtendForValue(&I);
+      // Decide the preferred extend type for a value. This iterates over all
+      // users and therefore isn't cheap, so don't do this at O0.
+      if (DAG->getOptLevel() != CodeGenOptLevel::None)
+        PreferredExtendType[&I] = getPreferredExtendForValue(&I);
     }
   }
 

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

@aengelke aengelke merged commit 0c7d268 into llvm:main May 19, 2024
6 checks passed
@aengelke aengelke deleted the perf/sdag-o0-noprefext branch May 19, 2024 14:38
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.

3 participants