[llvm] 8aefa2b - [InstCombine] Don't remove non-terminator unreachable markers

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 06:52:59 PDT 2023


Author: Nikita Popov
Date: 2023-06-22T15:52:52+02:00
New Revision: 8aefa2bf392ec7a82f2eceba241ae0fac9e5d42e

URL: https://github.com/llvm/llvm-project/commit/8aefa2bf392ec7a82f2eceba241ae0fac9e5d42e
DIFF: https://github.com/llvm/llvm-project/commit/8aefa2bf392ec7a82f2eceba241ae0fac9e5d42e.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    llvm/test/Transforms/InstCombine/constant-fold-shifts.ll
    llvm/test/Transforms/InstCombine/not-add.ll
    llvm/test/Transforms/InstCombine/phi.ll
    llvm/test/Transforms/InstCombine/udiv-simplify.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index b7d1074c65cf6..1843c121850b6 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<UndefValue>(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 bcbfdbb09cbdc..5b2c8d0279754 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 4fab55d6e7a12..43d269f0ecc07 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 52a5c0b3a2d74..310b5fbf7fda2 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 6971b6c915b58..d7b300e98f1d7 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


        


More information about the llvm-commits mailing list