[llvm] [ConstantFolding] Fix type mismatch in ConstantFolding for vector types. (PR #181695)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 11:44:08 PST 2026
================
@@ -827,7 +827,7 @@ Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1,
if (IsConstantOffsetFromGlobal(Op0, GV1, Offs1, DL))
if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, DL) && GV1 == GV2) {
- unsigned OpSize = DL.getTypeSizeInBits(Op0->getType());
+ unsigned OpSize = DL.getTypeSizeInBits(Op0->getType()->getScalarType());
----------------
nikic wrote:
I think the underlying problem is really in IsConstantOffsetFromGlobal. This should not be detected as a "constant offset from global". I believe that https://github.com/maarquitos14/llvm-project/blob/95a4015abfefa93fff043032974c6b755cd72259/llvm/lib/Analysis/ConstantFolding.cpp#L333 mistakenly assumed that this is looking past a ptr-to-ptr bitcast, and did not consider the possibility of other bitcasts. With opaque pointers, the bitcast case there can probably just be dropped entirely, which should also fix this issue.
https://github.com/llvm/llvm-project/pull/181695
More information about the llvm-commits
mailing list