@@ -1800,10 +1800,10 @@ void X86DAGToDAGISel::emitFunctionEntryCode() {
18001800 emitSpecialCodeForMain ();
18011801}
18021802
1803- static bool isDispSafeForFrameIndex (int64_t Val) {
1804- // On 64-bit platforms, we can run into an issue where a frame index
1803+ static bool isDispSafeForFrameIndexOrRegBase (int64_t Val) {
1804+ // We can run into an issue where a frame index or a register base
18051805 // includes a displacement that, when added to the explicit displacement,
1806- // will overflow the displacement field. Assuming that the frame index
1806+ // will overflow the displacement field. Assuming that the
18071807 // displacement fits into a 31-bit integer (which is only slightly more
18081808 // aggressive than the current fundamental assumption that it fits into
18091809 // a 32-bit integer), a 31-bit disp should always be safe.
@@ -1831,7 +1831,7 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset,
18311831 // In addition to the checks required for a register base, check that
18321832 // we do not try to use an unsafe Disp with a frame index.
18331833 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
1834- !isDispSafeForFrameIndex (Val))
1834+ !isDispSafeForFrameIndexOrRegBase (Val))
18351835 return true ;
18361836 // In ILP32 (x32) mode, pointers are 32 bits and need to be zero-extended to
18371837 // 64 bits. Instructions with 32-bit register addresses perform this zero
@@ -1849,10 +1849,14 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset,
18491849 // to get an address size override to be emitted. However, this
18501850 // pseudo-register is not part of any register class and therefore causes
18511851 // MIR verification to fail.
1852- if (Subtarget->isTarget64BitILP32 () && !isUInt<31 >(Val) &&
1852+ if (Subtarget->isTarget64BitILP32 () &&
1853+ !isDispSafeForFrameIndexOrRegBase ((uint32_t )Val) &&
18531854 !AM.hasBaseOrIndexReg ())
18541855 return true ;
1855- }
1856+ } else if (AM.hasBaseOrIndexReg () && !isDispSafeForFrameIndexOrRegBase (Val))
1857+ // For 32-bit X86, make sure the displacement still isn't close to the
1858+ // expressible limit.
1859+ return true ;
18561860 AM.Disp = Val;
18571861 return false ;
18581862}
@@ -2553,7 +2557,7 @@ bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM,
25532557 case ISD::FrameIndex:
25542558 if (AM.BaseType == X86ISelAddressMode::RegBase &&
25552559 AM.Base_Reg .getNode () == nullptr &&
2556- (!Subtarget->is64Bit () || isDispSafeForFrameIndex (AM.Disp ))) {
2560+ (!Subtarget->is64Bit () || isDispSafeForFrameIndexOrRegBase (AM.Disp ))) {
25572561 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
25582562 AM.Base_FrameIndex = cast<FrameIndexSDNode>(N)->getIndex ();
25592563 return false ;
0 commit comments