From 8aefa2bf392ec7a82f2eceba241ae0fac9e5d42e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 22 Jun 2023 15:50:22 +0200 Subject: [PATCH] [InstCombine] Don't remove non-terminator unreachable markers Even if the value happens to be undef, we should preserve these so they get turned into an unreachable terminator later. --- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 4 ++++ llvm/test/Transforms/InstCombine/constant-fold-shifts.ll | 2 ++ llvm/test/Transforms/InstCombine/not-add.ll | 1 + llvm/test/Transforms/InstCombine/phi.ll | 1 + llvm/test/Transforms/InstCombine/udiv-simplify.ll | 1 + 5 files changed, 9 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index b7d1074..1843c12 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -1559,6 +1559,10 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) { return nullptr; // Do not modify these! } + // This is a non-terminator unreachable marker. Don't remove it. + if (isa(Ptr)) + return nullptr; + // store undef, Ptr -> noop // FIXME: This is technically incorrect because it might overwrite a poison // value. Change to PoisonValue once #52930 is resolved. diff --git a/llvm/test/Transforms/InstCombine/constant-fold-shifts.ll b/llvm/test/Transforms/InstCombine/constant-fold-shifts.ll index bcbfdbb0..5b2c8d0 100644 --- a/llvm/test/Transforms/InstCombine/constant-fold-shifts.ll +++ b/llvm/test/Transforms/InstCombine/constant-fold-shifts.ll @@ -8,6 +8,7 @@ define void @ossfuzz_14169_test1(ptr %a0) { ; CHECK-LABEL: @ossfuzz_14169_test1( ; CHECK-NEXT: bb: +; CHECK-NEXT: store ptr undef, ptr undef, align 8 ; CHECK-NEXT: ret void ; bb: @@ -23,6 +24,7 @@ bb: define void @ossfuzz_14169_test2(ptr %a0) { ; CHECK-LABEL: @ossfuzz_14169_test2( ; CHECK-NEXT: bb: +; CHECK-NEXT: store ptr undef, ptr undef, align 8 ; CHECK-NEXT: ret void ; bb: diff --git a/llvm/test/Transforms/InstCombine/not-add.ll b/llvm/test/Transforms/InstCombine/not-add.ll index 4fab55d..43d269f 100644 --- a/llvm/test/Transforms/InstCombine/not-add.ll +++ b/llvm/test/Transforms/InstCombine/not-add.ll @@ -170,6 +170,7 @@ cond.end: define void @pr50370(i32 %x) { ; CHECK-LABEL: @pr50370( ; CHECK-NEXT: entry: +; CHECK-NEXT: store i32 poison, ptr undef, align 4 ; CHECK-NEXT: ret void ; entry: diff --git a/llvm/test/Transforms/InstCombine/phi.ll b/llvm/test/Transforms/InstCombine/phi.ll index 52a5c0b..310b5fb 100644 --- a/llvm/test/Transforms/InstCombine/phi.ll +++ b/llvm/test/Transforms/InstCombine/phi.ll @@ -1301,6 +1301,7 @@ define void @main(i1 %cond, i16 %x) { ; CHECK: g.exit: ; CHECK-NEXT: br label [[FOR_COND]] ; CHECK: for.end: +; CHECK-NEXT: store double undef, ptr undef, align 8 ; CHECK-NEXT: ret void ; entry: diff --git a/llvm/test/Transforms/InstCombine/udiv-simplify.ll b/llvm/test/Transforms/InstCombine/udiv-simplify.ll index 6971b6c..d7b300e 100644 --- a/llvm/test/Transforms/InstCombine/udiv-simplify.ll +++ b/llvm/test/Transforms/InstCombine/udiv-simplify.ll @@ -67,6 +67,7 @@ define i32 @PR30366(i1 %a) { ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4857 define i177 @ossfuzz_4857(i177 %X, i177 %Y) { ; CHECK-LABEL: @ossfuzz_4857( +; CHECK-NEXT: store i1 poison, ptr undef, align 1 ; CHECK-NEXT: ret i177 0 ; %B5 = udiv i177 %Y, -1 -- 2.7.4