[llvm] [IR] Only follow ptr/ptr-vector sources in stripAndAccumulateConstantOffsets bitcasts (PR #203356)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 12:55:33 PDT 2026


================
@@ -2011,4 +2011,54 @@ TEST(InstructionsTest, StripAndAccumulateConstantOffset) {
   EXPECT_TRUE(Offset.isZero());
 }
 
+// stripAndAccumulateConstantOffsets must only look through ptr->ptr (or
+// ptr-vector) bitcasts, matching stripPointerCastsAndOffsets. Following a
+// bitcast from a non-pointer (e.g. lossless iN->ptr) would leave a non-pointer
+// V and violate the strip loop invariant.
+TEST(InstructionsTest, StripAndAccumulateConstantOffsets_ThroughPtrBitCast) {
----------------
gandhi56 wrote:

Technically yes - by running instcombine with a multiple casts around a `ptr` but it can get messy. Unit tests seem rather simpler and targeted in comparison.

https://github.com/llvm/llvm-project/pull/203356


More information about the llvm-commits mailing list