[llvm] 7c12418 - [GISel] Avoid creating a virtual register we don't need. (#119305)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 9 20:23:28 PST 2024


Author: Craig Topper
Date: 2024-12-09T20:23:24-08:00
New Revision: 7c12418021a97545d7e76c876464291932f151e6

URL: https://github.com/llvm/llvm-project/commit/7c12418021a97545d7e76c876464291932f151e6
DIFF: https://github.com/llvm/llvm-project/commit/7c12418021a97545d7e76c876464291932f151e6.diff

LOG: [GISel] Avoid creating a virtual register we don't need. (#119305)

narrowScalarAddSub was creating a virtual register and then overwriting
the Register variable without using it. Add an else and only create it
when needed.

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index cf835ad187f818..5bfeee05a19c0d 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -6406,10 +6406,12 @@ LegalizerHelper::narrowScalarAddSub(MachineInstr &MI, unsigned TypeIdx,
   for (int i = 0, e = Src1Regs.size(); i != e; ++i) {
     Register DstReg =
         MRI.createGenericVirtualRegister(MRI.getType(Src1Regs[i]));
-    Register CarryOut = MRI.createGenericVirtualRegister(LLT::scalar(1));
+    Register CarryOut;
     // Forward the final carry-out to the destination register
     if (i == e - 1 && CarryDst)
       CarryOut = CarryDst;
+    else
+      CarryOut = MRI.createGenericVirtualRegister(LLT::scalar(1));
 
     if (!CarryIn) {
       MIRBuilder.buildInstr(OpO, {DstReg, CarryOut},


        


More information about the llvm-commits mailing list