@@ -1800,10 +1800,10 @@ void X86DAGToDAGISel::emitFunctionEntryCode() {
1800
1800
emitSpecialCodeForMain ();
1801
1801
}
1802
1802
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
1805
1805
// 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
1807
1807
// displacement fits into a 31-bit integer (which is only slightly more
1808
1808
// aggressive than the current fundamental assumption that it fits into
1809
1809
// a 32-bit integer), a 31-bit disp should always be safe.
@@ -1831,7 +1831,7 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset,
1831
1831
// In addition to the checks required for a register base, check that
1832
1832
// we do not try to use an unsafe Disp with a frame index.
1833
1833
if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
1834
- !isDispSafeForFrameIndex (Val))
1834
+ !isDispSafeForFrameIndexOrRegBase (Val))
1835
1835
return true ;
1836
1836
// In ILP32 (x32) mode, pointers are 32 bits and need to be zero-extended to
1837
1837
// 64 bits. Instructions with 32-bit register addresses perform this zero
@@ -1849,10 +1849,14 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset,
1849
1849
// to get an address size override to be emitted. However, this
1850
1850
// pseudo-register is not part of any register class and therefore causes
1851
1851
// MIR verification to fail.
1852
- if (Subtarget->isTarget64BitILP32 () && !isUInt<31 >(Val) &&
1852
+ if (Subtarget->isTarget64BitILP32 () &&
1853
+ !isDispSafeForFrameIndexOrRegBase ((uint32_t )Val) &&
1853
1854
!AM.hasBaseOrIndexReg ())
1854
1855
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 ;
1856
1860
AM.Disp = Val;
1857
1861
return false ;
1858
1862
}
@@ -2553,7 +2557,7 @@ bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM,
2553
2557
case ISD::FrameIndex:
2554
2558
if (AM.BaseType == X86ISelAddressMode::RegBase &&
2555
2559
AM.Base_Reg .getNode () == nullptr &&
2556
- (!Subtarget->is64Bit () || isDispSafeForFrameIndex (AM.Disp ))) {
2560
+ (!Subtarget->is64Bit () || isDispSafeForFrameIndexOrRegBase (AM.Disp ))) {
2557
2561
AM.BaseType = X86ISelAddressMode::FrameIndexBase;
2558
2562
AM.Base_FrameIndex = cast<FrameIndexSDNode>(N)->getIndex ();
2559
2563
return false ;
0 commit comments