[llvm] 1098acd - GlobalISel: Avoid unnecessary truncation to i64

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 21 07:21:51 PDT 2021


Author: Matt Arsenault
Date: 2021-03-21T10:07:41-04:00
New Revision: 1098acd46d4768a01c57ec319905cc6032ad1732

URL: https://github.com/llvm/llvm-project/commit/1098acd46d4768a01c57ec319905cc6032ad1732
DIFF: https://github.com/llvm/llvm-project/commit/1098acd46d4768a01c57ec319905cc6032ad1732.diff

LOG: GlobalISel: Avoid unnecessary truncation to i64

We can just directly pass through the APInt to create a new constant.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
index 2c86f06a602d..82942b9476dd 100644
--- a/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
@@ -189,7 +189,7 @@ MachineInstrBuilder CSEMIRBuilder::buildInstr(unsigned Opc,
     assert(DstOps.size() == 1 && "Invalid dsts");
     if (Optional<APInt> Cst = ConstantFoldBinOp(Opc, SrcOps[0].getReg(),
                                                 SrcOps[1].getReg(), *getMRI()))
-      return buildConstant(DstOps[0], Cst->getSExtValue());
+      return buildConstant(DstOps[0], *Cst);
     break;
   }
   case TargetOpcode::G_SEXT_INREG: {
@@ -200,7 +200,7 @@ MachineInstrBuilder CSEMIRBuilder::buildInstr(unsigned Opc,
     const SrcOp &Src1 = SrcOps[1];
     if (auto MaybeCst =
             ConstantFoldExtOp(Opc, Src0.getReg(), Src1.getImm(), *getMRI()))
-      return buildConstant(Dst, MaybeCst->getSExtValue());
+      return buildConstant(Dst, *MaybeCst);
     break;
   }
   }


        


More information about the llvm-commits mailing list