[llvm] ee3068b - [ConstantFolding] Fix type mismatch in ConstantFolding for vector types. (#181695)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 18 10:49:45 PST 2026
Author: Marcos Maronas
Date: 2026-02-18T18:49:40Z
New Revision: ee3068bd18b23ceb30c0464395fa182cfa28a5fb
URL: https://github.com/llvm/llvm-project/commit/ee3068bd18b23ceb30c0464395fa182cfa28a5fb
DIFF: https://github.com/llvm/llvm-project/commit/ee3068bd18b23ceb30c0464395fa182cfa28a5fb.diff
LOG: [ConstantFolding] Fix type mismatch in ConstantFolding for vector types. (#181695)
Drop `Bitcast` case from `IsConstantOffsetFromGlobal` to avoid
misdetections.
Added:
llvm/test/Transforms/InstSimplify/ConstProp/vector-type-constant-folding.ll
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index b0ac14ba8b393..738d0c063a5e4 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -329,8 +329,7 @@ bool llvm::IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
// Look through ptr->int and ptr->ptr casts.
if (CE->getOpcode() == Instruction::PtrToInt ||
- CE->getOpcode() == Instruction::PtrToAddr ||
- CE->getOpcode() == Instruction::BitCast)
+ CE->getOpcode() == Instruction::PtrToAddr)
return IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, DL,
DSOEquiv);
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/vector-type-constant-folding.ll b/llvm/test/Transforms/InstSimplify/ConstProp/vector-type-constant-folding.ll
new file mode 100644
index 0000000000000..5b12fd3ec545f
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/vector-type-constant-folding.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+;
+; Test type mismatch in ConstantFolding for vector types.
+
+define internal void @f() {
+; CHECK-LABEL: define internal void @f() {
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+
+define void @test() {
+; CHECK-LABEL: define void @test() {
+; CHECK-NEXT: store <4 x i16> <i16 sub (i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 0), i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 0)), i16 sub (i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 1), i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 1)), i16 sub (i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 2), i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 2)), i16 sub (i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 3), i16 extractelement (<4 x i16> bitcast (i64 ptrtoint (ptr @f to i64) to <4 x i16>), i32 3))>, ptr @f, align 8
+; CHECK-NEXT: ret void
+;
+ %1 = ptrtoint ptr @f to i64
+ %2 = bitcast i64 %1 to <4 x i16>
+ %3 = ptrtoint ptr @f to i64
+ %4 = bitcast i64 %3 to <4 x i16>
+ %sub = sub <4 x i16> %2, %4
+ store <4 x i16> %sub, ptr @f, align 8
+ ret void
+}
More information about the llvm-commits
mailing list