| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2026 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
/*========================== begin_copyright_notice ============================ |
| 10 |
|
| 11 |
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
See https://llvm.org/LICENSE.txt for license information. |
| 13 |
SPDX-License-Identifier: Apache-2.0 with LLVM-exception |
| 14 |
|
| 15 |
============================= end_copyright_notice ===========================*/ |
| 16 |
|
| 17 |
We've observed that in some cases (e.g this test: https://github.com/intel/intel-graphics-compiler/blob/master/IGC/ocloc_tests/retry/final_test_pytorch3.ll) |
| 18 |
whole function's body is removed when it shouldn't. |
| 19 |
|
| 20 |
This patch makes InstructionCombiner behaviour consistent with LLVM 16 by disabling part of removal logic. |
| 21 |
In upstream it was handled/fixed like this: |
| 22 |
https://github.com/llvm/llvm-project/commit/70aca7b12220971dcc54ec6431813665eac5856e |
| 23 |
|
| 24 |
I think this patch can be removed once we switch to LLVM 18 or later. |
| 25 |
|
| 26 |
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp |
| 27 |
index 6aa20ee26..5d0e5d00b 100644 |
| 28 |
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp |
| 29 |
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp |
| 30 |
@@ -1559,14 +1559,14 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) { |
| 31 |
} |
| 32 |
|
| 33 |
// This is a non-terminator unreachable marker. Don't remove it. |
| 34 |
- if (isa<UndefValue>(Ptr)) { |
| 35 |
- // Remove all instructions after the marker and guaranteed-to-transfer |
| 36 |
- // instructions before the marker. |
| 37 |
- if (handleUnreachableFrom(SI.getNextNode()) || |
| 38 |
- removeInstructionsBeforeUnreachable(SI)) |
| 39 |
- return &SI; |
| 40 |
- return nullptr; |
| 41 |
- } |
| 42 |
+ // if (isa<UndefValue>(Ptr)) { |
| 43 |
+ // // Remove all instructions after the marker and guaranteed-to-transfer |
| 44 |
+ // // instructions before the marker. |
| 45 |
+ // if (handleUnreachableFrom(SI.getNextNode()) || |
| 46 |
+ // removeInstructionsBeforeUnreachable(SI)) |
| 47 |
+ // return &SI; |
| 48 |
+ // return nullptr; |
| 49 |
+ // } |
| 50 |
|
| 51 |
// store undef, Ptr -> noop |
| 52 |
// FIXME: This is technically incorrect because it might overwrite a poison |