Skip to content

Commit 1604f5d

Browse files
ekochetkigcbot
authored andcommitted
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.
1 parent 291b7ed commit 1604f5d

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
@@ -785,6 +785,37 @@ void CustomSafeOptPass::visitCallInst(CallInst& C)
785785
}
786786
}
787787

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

789820
//
790821
// 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)