[llvm] [WPD] Remove type test assumes through PHI and select nodes (PR #224155)

Michael Park via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 01:05:36 PDT 2026


================
@@ -0,0 +1,172 @@
+; Regression tests for https://github.com/llvm/llvm-project/issues/187049.
+;
+; Test that WPD removes type test assumes that are merged through a select or
+; phi when there are no corresponding vtables in the ThinLTO index. If an
+; assume is left behind, LowerTypeTests resolves the type tests to false,
+; producing assume(false) and incorrectly making the virtual call unreachable.
+;
+; REQUIRES: x86-registered-target
+;
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit=false -o %t.o %s
+; RUN: llvm-lto2 run %t.o -save-temps -whole-program-visibility \
+; RUN:   -r=%t.o,test_select,plx \
+; RUN:   -r=%t.o,test_select_one_missing,plx \
+; RUN:   -r=%t.o,test_select_chain,plx \
+; RUN:   -r=%t.o,test_phi,plx \
+; RUN:   -r=%t.o,seed_known,plx \
+; RUN:   -r=%t.o,get_base, \
+; RUN:   -r=%t.o,get_derived, \
+; RUN:   -r=%t.o,observe, \
+; RUN:   -r=%t.o,puts, \
+; RUN:   -o %t2
+; RUN: llvm-dis %t2.1.4.opt.bc -o - | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at message = private unnamed_addr constant [6 x i8] c"hello\00"
+ at known_vtable = internal constant [1 x ptr] [ptr @known_target], !type !0
+ at llvm.compiler.used = appending global [1 x ptr] [ptr @known_vtable],
+    section "llvm.metadata"
+
+define void @test_select(ptr %object, i1 %derived) {
+entry:
+  %vtable = load ptr, ptr %object, align 8
+  %base.test = call i1 @llvm.public.type.test(
+      ptr %vtable, metadata !"_ZTS4Base")
+  %derived.test = call i1 @llvm.public.type.test(
+      ptr %vtable, metadata !"_ZTS7Derived")
+  %type.test = select i1 %derived, i1 %derived.test, i1 %base.test
+  call void @llvm.assume(i1 %type.test)
+  %target = load ptr, ptr %vtable, align 8
+  call void %target(ptr %object)
+  call i32 @puts(ptr @message)
+  ret void
+}
+
+; CHECK-LABEL: @test_select(
+; CHECK-NOT: @llvm.type.test
----------------
mpark wrote:

Yep. Updated to do this now. Thanks!

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


More information about the llvm-commits mailing list