Skip to content

Commit 53227ba

Browse files
ekochetkArtem Gindinson
authored and
Artem Gindinson
committed
Move select-to-logical peephole earlier in pipeline
Currently the peephole is applied on GenSpecificOpt but it is needed by SimplifyCFG. Now applying it earlier in CustomSafeOpt. (cherry picked from commit 1604f5d)
1 parent 6a8c073 commit 53227ba

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2022 Intel Corporation
3+
Copyright (C) 2017-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -782,6 +782,37 @@ void CustomSafeOptPass::visitCallInst(CallInst& C)
782782
}
783783
}
784784

785+
void CustomSafeOptPass::visitSelectInst(SelectInst& I)
786+
{
787+
// select i1 %x, 1, %y -> or i1 %x, %y
788+
// select i1 %x, %y, 0 -> and i1 %x, %y
789+
790+
using namespace llvm::PatternMatch;
791+
llvm::IRBuilder<> Builder(&I);
792+
793+
if (I.getType()->isIntegerTy(1) && match(&I, m_Select(m_Value(), m_SpecificInt(1), m_Value())))
794+
{
795+
auto NewVal = Builder.CreateOr(I.getOperand(0), I.getOperand(2));
796+
Instruction *OrInst = dyn_cast<Instruction>(NewVal);
797+
if (OrInst)
798+
{
799+
OrInst->setDebugLoc(I.getDebugLoc());
800+
}
801+
I.replaceAllUsesWith(NewVal);
802+
}
803+
804+
if (I.getType()->isIntegerTy(1) && match(&I, m_Select(m_Value(), m_Value(), m_SpecificInt(0))))
805+
{
806+
auto NewVal = Builder.CreateAnd(I.getOperand(0), I.getOperand(1));
807+
Instruction *AndInst = dyn_cast<Instruction>(NewVal);
808+
if (AndInst)
809+
{
810+
AndInst->setDebugLoc(I.getDebugLoc());
811+
}
812+
I.replaceAllUsesWith(NewVal);
813+
}
814+
}
815+
785816

786817
//
787818
// pattern match packing of two half float from f32tof16:

IGC/Compiler/CustomSafeOptPass.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2021 Intel Corporation
3+
Copyright (C) 2017-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -75,6 +75,7 @@ namespace IGC
7575
void visitAnd(llvm::BinaryOperator& I);
7676
void visitXor(llvm::Instruction& XorInstr);
7777
void visitShuffleIndex(llvm::CallInst* I);
78+
void visitSelectInst(llvm::SelectInst& S);
7879
//
7980
// IEEE Floating point arithmetic is not associative. Any pattern
8081
// match that changes the order or paramters is unsafe.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -debugify --igc-custom-safe-opt -check-debugify -S < %s 2>&1 | FileCheck %s
10+
11+
; Debug-info related check
12+
; CHECK-NOT: WARNING
13+
; CHECK: CheckModuleDebugify: PASS
14+
15+
define spir_kernel void @test_select_and(i1 %srca, i1 %srcb) {
16+
; CHECK-LABEL: @test_select_and(
17+
; CHECK: [[TMP:%[A-z0-9]*]] = and i1 %srca, %srcb
18+
; CHECK: call void @use.i1(i1 [[TMP]])
19+
; CHECK: ret void
20+
;
21+
%1 = select i1 %srca, i1 %srcb, i1 false
22+
call void @use.i1(i1 %1)
23+
ret void
24+
}
25+
26+
define spir_kernel void @test_select_or(i1 %srca, i1 %srcb) {
27+
; CHECK-LABEL: @test_select_or(
28+
; CHECK: [[TMP:%[A-z0-9]*]] = or i1 %srca, %srcb
29+
; CHECK: call void @use.i1(i1 [[TMP]])
30+
; CHECK: ret void
31+
;
32+
%1 = select i1 %srca, i1 true, i1 %srcb
33+
call void @use.i1(i1 %1)
34+
ret void
35+
}
36+
37+
declare void @use.i1(i1)

0 commit comments

Comments
 (0)