[llvm] 587573b - [CSKY] Fix the assert in eliminateFrameIndex when the offset is negative

Zi Xuan Wu via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 18:56:23 PDT 2022


Author: Zi Xuan Wu (Zeson)
Date: 2022-06-15T09:54:21+08:00
New Revision: 587573b9f9f74fdb3f816ca6de72b3ecdc6441d3

URL: https://github.com/llvm/llvm-project/commit/587573b9f9f74fdb3f816ca6de72b3ecdc6441d3
DIFF: https://github.com/llvm/llvm-project/commit/587573b9f9f74fdb3f816ca6de72b3ecdc6441d3.diff

LOG: [CSKY] Fix the assert in eliminateFrameIndex when the offset is negative

After the frameindex is resolved, the offset can be negative. It would
be materialized as unsigned integer and can still calculated by add instruction.

Added: 
    

Modified: 
    llvm/lib/Target/CSKY/CSKYInstrInfo.cpp
    llvm/lib/Target/CSKY/CSKYInstrInfo.h
    llvm/lib/Target/CSKY/CSKYRegisterInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/CSKY/CSKYInstrInfo.cpp b/llvm/lib/Target/CSKY/CSKYInstrInfo.cpp
index 5eb7bb700790e..d490b385ac16d 100644
--- a/llvm/lib/Target/CSKY/CSKYInstrInfo.cpp
+++ b/llvm/lib/Target/CSKY/CSKYInstrInfo.cpp
@@ -223,9 +223,10 @@ bool CSKYInstrInfo::reverseBranchCondition(
 
 Register CSKYInstrInfo::movImm(MachineBasicBlock &MBB,
                                MachineBasicBlock::iterator MBBI,
-                               const DebugLoc &DL, int64_t Val,
+                               const DebugLoc &DL, uint64_t Val,
                                MachineInstr::MIFlag Flag) const {
-  assert(isUInt<32>(Val) && "should be uint32");
+  if (!isInt<32>(Val))
+    report_fatal_error("Should only materialize 32-bit constants.");
 
   MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
 

diff  --git a/llvm/lib/Target/CSKY/CSKYInstrInfo.h b/llvm/lib/Target/CSKY/CSKYInstrInfo.h
index 1a1bbbf9154f7..a979b0bf4b0db 100644
--- a/llvm/lib/Target/CSKY/CSKYInstrInfo.h
+++ b/llvm/lib/Target/CSKY/CSKYInstrInfo.h
@@ -79,7 +79,7 @@ class CSKYInstrInfo : public CSKYGenInstrInfo {
 
   // Materializes the given integer Val into DstReg.
   Register movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
-                  const DebugLoc &DL, int64_t Val,
+                  const DebugLoc &DL, uint64_t Val,
                   MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const;
 };
 

diff  --git a/llvm/lib/Target/CSKY/CSKYRegisterInfo.cpp b/llvm/lib/Target/CSKY/CSKYRegisterInfo.cpp
index f811c834c260a..4f7811d22868e 100644
--- a/llvm/lib/Target/CSKY/CSKYRegisterInfo.cpp
+++ b/llvm/lib/Target/CSKY/CSKYRegisterInfo.cpp
@@ -265,7 +265,6 @@ void CSKYRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
     assert(isInt<32>(Offset) && "Int32 expected");
     // The offset won't fit in an immediate, so use a scratch register instead
     // Modify Offset and FrameReg appropriately
-    assert(Offset >= 0);
     Register ScratchReg = TII->movImm(MBB, NewII, DL, Offset);
     BuildMI(MBB, NewII, DL,
             TII->get(STI.hasE2() ? CSKY::ADDU32 : CSKY::ADDU16XZ), ScratchReg)


        


More information about the llvm-commits mailing list