[llvm] [GVN] Skip instructions without value numbers in performScalarPRE (PR #219851)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 02:33:24 PDT 2026


================
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=gvn -S < %s | FileCheck %s
+
+; Test for #216265. When GVN forwards the vector store to the i64 load, it
+; inserts a coercion bitcast that has no value number yet. Processing the
+; PRE'd load of %gep afterwards runs scalar PRE on the GEP index (now the
+; bitcast) and used to assert with "Value not numbered?".
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+
+ at g14 = external global i64
+ at g23 = external global <2 x i32>
+
+define void @f2() {
+; CHECK-LABEL: define void @f2() {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[ARR:%.*]] = alloca [9 x i8], align 1
+; CHECK-NEXT:    [[V:%.*]] = load <2 x i32>, ptr @g14, align 8
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[TMP0:%.*]], %[[LOOP]] ]
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[ARR]], i64 [[IV]]
+; CHECK-NEXT:    store <2 x i32> [[V]], ptr @g23, align 8
+; CHECK-NEXT:    [[TMP0]] = bitcast <2 x i32> [[V]] to i64
+; CHECK-NEXT:    [[GEP_PHI_TRANS_INSERT:%.*]] = getelementptr inbounds i8, ptr [[ARR]], i64 [[TMP0]]
+; CHECK-NEXT:    br label %[[LOOP]]
+;
+entry:
+  %arr = alloca [9 x i8], align 1
+  %v = load <2 x i32>, ptr @g14, align 8
+  br label %loop
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %conv, %loop ]
+  %gep = getelementptr inbounds i8, ptr %arr, i64 %iv
+  %load1 = load i8, ptr %gep, align 1
----------------
antoniofrighetto wrote:

We are dereferencing a poison pointer on the second iteration (immediate UB). Is it possible to craft a minimal reproducer triggering the issue without introducing UB?

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


More information about the llvm-commits mailing list