[llvm-branch-commits] [llvm] [ConstantFolding] Set signed/implicitTrunc when handling GEP offsets (PR #116864)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 19 11:46:18 PST 2024
https://github.com/AreaZR created https://github.com/llvm/llvm-project/pull/116864
GEP offsets have sext_or_trunc semantics. We were already doing this for the outer-most GEP, but not for the inner ones.
I believe one of the sanitizer buildbot failures was due to this, but I did not manage to reproduce the issue or come up with a test case. Usually the problematic case will already be folded away due to index type canonicalization.
(cherry picked from commit a18dd29077c84fc076a4ed431d9e815a3d0b6f24)
>From 21ad24551ae3017b13b3c8141a08738bc2894729 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Mon, 21 Oct 2024 12:42:47 +0200
Subject: [PATCH] [ConstantFolding] Set signed/implicitTrunc when handling GEP
offsets
GEP offsets have sext_or_trunc semantics. We were already doing
this for the outer-most GEP, but not for the inner ones.
I believe one of the sanitizer buildbot failures was due to this,
but I did not manage to reproduce the issue or come up with a
test case. Usually the problematic case will already be folded
away due to index type canonicalization.
(cherry picked from commit a18dd29077c84fc076a4ed431d9e815a3d0b6f24)
---
llvm/lib/Analysis/ConstantFolding.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index ff30fece5fce93..a73f3c7ded78be 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -924,7 +924,8 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
Ptr = cast<Constant>(GEP->getOperand(0));
SrcElemTy = GEP->getSourceElementType();
Offset = Offset.sadd_ov(
- APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps)),
+ APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps),
+ /*isSigned=*/true, /*implicitTrunc=*/true),
Overflow);
}
More information about the llvm-branch-commits
mailing list