Debian Codegraph @

external/llvm/releases/17.0.0/patches_external/instruction-simplify-pointerICMP-strip-casts.patch

raw
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 This PR reverts removal of stripPointerCasts in computePointerICmp which was done in this commit.
18
19 https://github.com/llvm/llvm-project/commit/793eb0c0e4ffadc1cfebcda0c0cb1bcc2311def2
20
21 I've found that in some case(s) it caused e.g function inliner to fail where on LLVM 16 it worked better.
22
23 Repro, where on LLVM 16 "%1 = icmp eq i64 %0, 0" is fully removed
24
25 ; Function Attrs: nounwind
26 define spir_kernel void @main1(i1 %branch1, i1 %branch2) {
27 entry:
28 %kernel = alloca i32, align 8
29
30 %bitcast1 = bitcast ptr %kernel to ptr
31 %data = getelementptr inbounds i8, ptr %bitcast1, i64 8
32 %data2 = addrspacecast ptr %data to ptr addrspace(4)
33 br i1 %branch1, label %callBranch, label %exit
34
35 callBranch:
36 call spir_func void @main2(ptr addrspace(4) align 8 dereferenceable(40) %data2, i1 %branch2)
37 br label %exit
38
39 exit:
40 ret void
41 }
42
43 ; Function Attrs: alwaysinline nounwind
44 define internal spir_func void @main2(ptr addrspace(4) align 8 dereferenceable(40) %data, i1 %branch2)
45 {
46 entry:
47 %args17 = alloca i32, align 8
48 br i1 %branch2, label %if.else, label %exit
49
50 if.else:
51 %args17.ascast = addrspacecast ptr %args17 to ptr addrspace(4)
52 call spir_func void @main3(ptr addrspace(4) %args17.ascast)
53 br label %exit
54
55 exit:
56 ret void
57 }
58
59 ; Function Attrs: alwaysinline nounwind
60 define internal spir_func void @main3(ptr addrspace(4) %args) {
61 entry:
62 %default_args = alloca i32, align 8
63 %0 = ptrtoint ptr addrspace(4) %args to i64
64 %1 = icmp eq i64 %0, 0
65 br i1 %1, label %branch1, label %branch2
66
67 branch1:
68 %default_args.ascast = addrspacecast ptr %default_args to ptr addrspace(4)
69 br label %combined
70
71 branch2:
72 %src = bitcast ptr addrspace(4) %args to ptr addrspace(4)
73 br label %combined
74
75 combined:
76 %args.addr.017 = phi ptr addrspace(4) [ %default_args.ascast, %branch1 ], [ %src, %branch2 ]
77 store ptr addrspace(4) %args, ptr addrspace(4) %args.addr.017, align 4
78 br label %exit
79
80 exit:
81 ret void
82 }
83
84 diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
85 index 0bfea6140ab5..5daac2d08d61 100644
86 --- a/llvm/lib/Analysis/InstructionSimplify.cpp
87 +++ b/llvm/lib/Analysis/InstructionSimplify.cpp
88 @@ -2724,6 +2724,10 @@ static Constant *computePointerICmp(CmpInst::Predicate Pred, Value *LHS,
89 const Instruction *CxtI = Q.CxtI;
90 const InstrInfoQuery &IIQ = Q.IIQ;
91
92 + // First, skip past any trivial no-ops.
93 + LHS = LHS->stripPointerCasts();
94 + RHS = RHS->stripPointerCasts();
95 +
96 // A non-null pointer is not equal to a null pointer.
97 if (isa<ConstantPointerNull>(RHS) && ICmpInst::isEquality(Pred) &&
98 llvm::isKnownNonZero(LHS, DL, 0, nullptr, nullptr, nullptr,