Skip to content

Commit 44cc39b

Browse files
smilczekigcbot
authored andcommitted
CustomLoopOpt fp type mismatch fix
CustomLoopOpt attempts to create Fcmp inst with first operand being a floating point type and second operand being unconditionally f32. This can cause a type mismatch as first operand is not necessarily f32.
1 parent 380a925 commit 44cc39b

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

IGC/Compiler/CustomLoopOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ bool CustomLoopVersioning::processLoop(Loop* loop)
586586
FMF.setFast();
587587
irb.setFastMathFlags(FMF);
588588
Value* cond0 = irb.CreateFCmpOGT(
589-
var_CBLoad_preHdr, ConstantFP::get(irb.getFloatTy(), 1.0));
589+
var_CBLoad_preHdr, ConstantFP::get(var_CBLoad_preHdr->getType(), 1.0));
590590

591591
Value* cond1 = irb.CreateFCmpOLT(
592592
irb.CreateFMul(var_range_x, var_CBLoad_preHdr),
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; REQUIRES: llvm-14-plus
10+
; RUN: igc_opt --opaque-pointers -debugify -igc-custom-loop-opt -S < %s 2>&1 | FileCheck %s
11+
; ------------------------------------------------
12+
; CustomLoopVersioning
13+
; ------------------------------------------------
14+
15+
; This test checks that we're not creating a cmp inst with mismatched fp types.
16+
17+
define spir_kernel void @test_customloop(ptr addrspace(65549) %a, double %b, double %c, double %d) {
18+
entry:
19+
%aa = inttoptr i32 42 to ptr addrspace(65549)
20+
%cc = call double @llvm.maxnum.f64(double %c, double 3.000000e+00)
21+
%dd = call double @llvm.minnum.f64(double %d, double 2.000000e+00)
22+
br label %pre_header
23+
24+
pre_header:
25+
; CHECK: [[TMP:%.*]] = load double
26+
%0 = load double, ptr addrspace(65549) %aa, align 4
27+
%1 = fmul double %b, %0
28+
; CHECK: fcmp fast ogt double [[TMP]], 1.000000e+00
29+
br label %loop_body
30+
31+
loop_body:
32+
%2 = phi double [ %b, %pre_header ], [ %3, %loop_body ]
33+
%3 = phi double [ %1, %pre_header ], [ %7, %loop_body ]
34+
%4 = call double @llvm.maxnum.f64(double %cc, double %2)
35+
%5 = call double @llvm.minnum.f64(double %dd, double %3)
36+
%6 = load double, ptr addrspace(65549) %aa, align 4
37+
%7 = fmul double %3, %6
38+
%8 = fcmp ult double %3, %dd
39+
br i1 %8, label %loop_body, label %end
40+
41+
end:
42+
store double %3, ptr addrspace(65549) %a, align 4
43+
ret void
44+
}
45+
46+
47+
declare double @llvm.maxnum.f64(double, double) #0
48+
declare double @llvm.minnum.f64(double, double) #0
49+
50+
!igc.functions = !{!0}
51+
52+
!0 = !{ptr @test_customloop, !1}
53+
!1 = !{!2}
54+
!2 = !{!"function_type", i32 0}

0 commit comments

Comments
 (0)