Skip to content

PeepholeOpt: Remove subreg def check for bitcast #130086

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

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Mar 6, 2025

Subregister defs are illegal in SSA. Surprisingly this enables folding
into subregister insert patterns in one test.

Copy link
Contributor Author

arsenm commented Mar 6, 2025

@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

@llvm/pr-subscribers-backend-x86

Author: Matt Arsenault (arsenm)

Changes

Subregister defs are illegal in SSA. Surprisingly this enables folding
into subregister insert patterns in one test.


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/PeepholeOptimizer.cpp (+4-5)
  • (modified) llvm/test/CodeGen/X86/pr41619.ll (-2)
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index 4d0fd86eb216f..ec8e97f73546a 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -1923,11 +1923,8 @@ ValueTrackerResult ValueTracker::getNextSourceFromBitcast() {
   // Bitcasts with more than one def are not supported.
   if (Def->getDesc().getNumDefs() != 1)
     return ValueTrackerResult();
-  const MachineOperand DefOp = Def->getOperand(DefIdx);
-  if (DefOp.getSubReg() != DefSubReg)
-    // If we look for a different subreg, it means we want a subreg of the src.
-    // Bails as we do not support composing subregs yet.
-    return ValueTrackerResult();
+
+  assert(!Def->getOperand(DefIdx).getSubReg() && "no subregister defs in SSA");
 
   unsigned SrcIdx = Def->getNumOperands();
   for (unsigned OpIdx = DefIdx + 1, EndOpIdx = SrcIdx; OpIdx != EndOpIdx;
@@ -1950,6 +1947,8 @@ ValueTrackerResult ValueTracker::getNextSourceFromBitcast() {
   if (SrcIdx >= Def->getNumOperands())
     return ValueTrackerResult();
 
+  const MachineOperand &DefOp = Def->getOperand(DefIdx);
+
   // Stop when any user of the bitcast is a SUBREG_TO_REG, replacing with a COPY
   // will break the assumed guarantees for the upper bits.
   for (const MachineInstr &UseMI : MRI.use_nodbg_instructions(DefOp.getReg())) {
diff --git a/llvm/test/CodeGen/X86/pr41619.ll b/llvm/test/CodeGen/X86/pr41619.ll
index 88dcd7798f0c3..6bca77d05e9a9 100644
--- a/llvm/test/CodeGen/X86/pr41619.ll
+++ b/llvm/test/CodeGen/X86/pr41619.ll
@@ -6,8 +6,6 @@ define void @foo(double %arg) {
 ; CHECK-LABEL: foo:
 ; CHECK:       ## %bb.0: ## %bb
 ; CHECK-NEXT:    vmovq %xmm0, %rax
-; CHECK-NEXT:    vmovd %eax, %xmm0
-; CHECK-NEXT:    vmovq %xmm0, %rax
 ; CHECK-NEXT:    movl %eax, (%rax)
 ; CHECK-NEXT:    movq $0, (%rax)
 ; CHECK-NEXT:    retq

Copy link
Contributor Author

arsenm commented Mar 7, 2025

Merge activity

  • Mar 6, 7:26 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Mar 6, 7:41 PM EST: Graphite rebased this pull request as part of a merge.
  • Mar 6, 7:44 PM EST: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/peephole-opt/remove-subreg-def-check-for-insert-subreg branch 3 times, most recently from 590e663 to afdb224 Compare March 7, 2025 00:37
Base automatically changed from users/arsenm/peephole-opt/remove-subreg-def-check-for-insert-subreg to main March 7, 2025 00:40
Subregister defs are illegal in SSA. Surprisingly this enables folding
into subregister insert patterns in one test.
@arsenm arsenm force-pushed the users/arsenm/peephole-opt/remove-dead-subreg-def-check-for-bitcast branch from c7d0811 to a3c43f8 Compare March 7, 2025 00:41
@arsenm arsenm merged commit c22db56 into main Mar 7, 2025
6 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/peephole-opt/remove-dead-subreg-def-check-for-bitcast branch March 7, 2025 00:44
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Subregister defs are illegal in SSA. Surprisingly this enables folding
into subregister insert patterns in one test.
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.

3 participants