Skip to content

Commit a1f110e

Browse files
committed
add lit test
1 parent 886ed1a commit a1f110e

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

bin/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ target_link_libraries(triton-opt PRIVATE
1313
TritonTransforms
1414
TritonGPUTransforms
1515
TritonNvidiaGPUTransforms
16+
TritonIntelLLVMIR
17+
TritonIntelGPUIR
18+
TritonIntelGPUTransforms
1619
MLIRGPUToROCDLTransforms
1720
${dialect_libs}
1821
${conversion_libs}
@@ -88,6 +91,7 @@ target_link_libraries(triton-llvm-opt PRIVATE
8891
LLVMSupport
8992
LLVMOption
9093
LLVMCodeGen
94+
TritonIntelLLVMIR
9195
TritonIntelGPUIR
9296
)
9397
export_executable_symbols_for_plugins(triton-llvm-opt)

bin/triton-llvm-opt.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Trimmed down clone of llvm opt to be able to test triton custom llvm ir
22
/// passes.
33
#include "lib/Target/LLVMIR/LLVMPasses.h"
4+
#include "third_party/intel/lib/LLVMIR/LLVMPasses.h"
45
#include "llvm/CodeGen/CommandFlags.h"
56
#include "llvm/IR/Constants.h"
67
#include "llvm/IR/DataLayout.h"
@@ -42,6 +43,11 @@ static cl::opt<bool>
4243
llvm::cl::desc("run pass to break phi struct"),
4344
cl::init(false));
4445

46+
static cl::opt<bool> FreezeMaskedDivRem(
47+
"freeze-masked-div-rem",
48+
llvm::cl::desc("run pass to insert freeze between masked load and div/rem"),
49+
cl::init(false));
50+
4551
namespace {
4652
static std::function<Error(Module *)> makeOptimizingPipeline() {
4753
return [](Module *m) -> Error {
@@ -62,6 +68,8 @@ static std::function<Error(Module *)> makeOptimizingPipeline() {
6268
llvm::FunctionPassManager fpm;
6369
if (BreakStructPhiNodes)
6470
fpm.addPass(BreakStructPhiNodesPass());
71+
if (FreezeMaskedDivRem)
72+
fpm.addPass(FreezeMaskedDivRemPass());
6573
mpm.addPass(createModuleToFunctionPassAdaptor(std::move(fpm)));
6674
mpm.run(*m, mam);
6775
return Error::success();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: triton-llvm-opt -freeze-masked-div-rem %s | FileCheck %s
2+
3+
define void @phi_div_of_zero_okay(i8 noundef %x, i8 %i, ptr %v) {
4+
; CHECK-LABEL: @phi_div_of_zero_okay(
5+
entry:
6+
%cmp = icmp ult i8 %i, 9
7+
br i1 %cmp, label %if.then, label %if.end
8+
9+
if.then:
10+
%y = load i8, ptr %v, align 8
11+
br label %if.end
12+
13+
if.end:
14+
%yy = phi i8 [ %y, %if.then ], [ 0, %entry ]
15+
; CHECK: [[F0:%.*]] = freeze i8 %yy
16+
; CHECK-NEXT: %z = sdiv i8 %x, [[F0:%.*]]
17+
%z = sdiv i8 %x, %yy
18+
br i1 %cmp, label %if2.then, label %if2.end
19+
20+
if2.then:
21+
store i8 %z, ptr %v, align 8
22+
br label %if2.end
23+
24+
if2.end:
25+
ret void
26+
}
27+
28+
define void @two_phi_div_of_zero_okay(i8 noundef %x, i8 %i, ptr %v) {
29+
; CHECK-LABEL: @two_phi_div_of_zero_okay(
30+
entry:
31+
%cmp = icmp ult i8 %i, 9
32+
br i1 %cmp, label %if.then, label %if.end
33+
34+
if.then:
35+
%y = load i8, ptr %v, align 8
36+
%vv = getelementptr inbounds i64, ptr %v, i64 1
37+
%b = load i8, ptr %vv, align 8
38+
br label %if.end
39+
40+
if.end:
41+
%bb = phi i8 [ %b, %if.then ], [ undef, %entry ]
42+
%yy = phi i8 [ %y, %if.then ], [ 0, %entry ]
43+
; CHECK: [[F0:%.*]] = freeze i8 %yy
44+
; CHECK-NEXT: %z = sdiv i8 %x, [[F0:%.*]]
45+
%z = sdiv i8 %x, %yy
46+
; CHECK: [[F1:%.*]] = freeze i8 %bb
47+
; CHECK-NEXT: %zz = sdiv i8 %x, [[F1:%.*]]
48+
%zz = sdiv i8 %x, %bb
49+
br i1 %cmp, label %if2.then, label %if2.end
50+
51+
if2.then:
52+
store i8 %z, ptr %v, align 8
53+
br label %if2.end
54+
55+
if2.end:
56+
ret void
57+
}

0 commit comments

Comments
 (0)