diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -17918,15 +17918,18 @@ if (Offset <= uint64_t(GN->getOffset())) return SDValue(); + uint64_t OffsetLimit = (1 << 21); + if (Subtarget->isTargetWindows()) + OffsetLimit = (1 << 20); // Check whether folding this offset is legal. It must not go out of bounds of // the referenced object to avoid violating the code model, and must be - // smaller than 2^21 because this is the largest offset expressible in all - // object formats. + // smaller than OffsetLimit because this is the largest offset expressible in + // the current object format. // // This check also prevents us from folding negative offsets, which will end // up being treated in the same way as large positive ones. They could also // cause code model violations, and aren't really common enough to matter. - if (Offset >= (1 << 21)) + if (Offset >= OffsetLimit) return SDValue(); const GlobalValue *GV = GN->getGlobal(); diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp @@ -161,15 +161,19 @@ if (NewOffset <= CurrOffset) return false; + uint64_t OffsetLimit = (1 << 21); + if (MF.getSubtarget().isTargetWindows()) + OffsetLimit = (1 << 20); + // Check whether folding this offset is legal. It must not go out of bounds of // the referenced object to avoid violating the code model, and must be - // smaller than 2^21 because this is the largest offset expressible in all - // object formats. + // smaller than OffsetLimit because this is the largest offset expressible in + // the current object format. // // This check also prevents us from folding negative offsets, which will end // up being treated in the same way as large positive ones. They could also // cause code model violations, and aren't really common enough to matter. - if (NewOffset >= (1 << 21)) + if (NewOffset >= OffsetLimit) return false; Type *T = GV->getValueType();