Skip to content

Conversation

@AZero13
Copy link
Contributor

@AZero13 AZero13 commented Nov 19, 2024

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 a18dd29)

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 a18dd29)
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Nov 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/pr-subscribers-llvm-analysis

Author: Rose (AreaZR)

Changes

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 a18dd29)


Full diff: https://github.com/llvm/llvm-project/pull/116864.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ConstantFolding.cpp (+2-1)
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);
   }
 

@AZero13 AZero13 changed the title [ConstantFolding] Set signed/implicitTrunc when handling GEP offsets release/19.x: [ConstantFolding] Set signed/implicitTrunc when handling GEP offsets Nov 19, 2024
@AZero13
Copy link
Contributor Author

AZero13 commented Nov 19, 2024

I am done finding things to backport to 19.x. Hopefully we do like one more round and release 19.1.6 but yeah.

@AZero13 AZero13 closed this Nov 19, 2024
@AZero13 AZero13 deleted the a1 branch November 19, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants