[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:51 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Rose (AreaZR)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/116864.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+2-1)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/116864
More information about the llvm-branch-commits
mailing list