[llvm] [CodeGenPrepare] Fix signed overflow (PR #141487)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 00:50:57 PDT 2025
================
@@ -5447,11 +5447,18 @@ bool AddressingModeMatcher::matchAddr(Value *Addr, unsigned Depth) {
TPT.getRestorationPoint();
if (ConstantInt *CI = dyn_cast<ConstantInt>(Addr)) {
if (CI->getValue().isSignedIntN(64)) {
- // Fold in immediates if legal for the target.
- AddrMode.BaseOffs += CI->getSExtValue();
- if (TLI.isLegalAddressingMode(DL, AddrMode, AccessTy, AddrSpace))
- return true;
- AddrMode.BaseOffs -= CI->getSExtValue();
+ // Check if the addition would result in a signed overflow.
+ bool Overflow = false;
+ APInt BaseOffs(64, AddrMode.BaseOffs, true);
+ APInt CIVal(64, CI->getValue().getSExtValue(), true);
+ auto Result = BaseOffs.sadd_ov(CIVal, Overflow);
+ if (!Overflow) {
----------------
mikael-nilsson-arm wrote:
Thanks, that is better.
https://github.com/llvm/llvm-project/pull/141487
More information about the llvm-commits
mailing list