Skip to content

Commit

Permalink
CustomLoopOpt fp type mismatch fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smilczek authored and igcbot committed Nov 12, 2024
1 parent 380a925 commit 44cc39b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion IGC/Compiler/CustomLoopOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ bool CustomLoopVersioning::processLoop(Loop* loop)
FMF.setFast();
irb.setFastMathFlags(FMF);
Value* cond0 = irb.CreateFCmpOGT(
var_CBLoad_preHdr, ConstantFP::get(irb.getFloatTy(), 1.0));
var_CBLoad_preHdr, ConstantFP::get(var_CBLoad_preHdr->getType(), 1.0));

Value* cond1 = irb.CreateFCmpOLT(
irb.CreateFMul(var_range_x, var_CBLoad_preHdr),
Expand Down
54 changes: 54 additions & 0 deletions IGC/Compiler/tests/CustomLoopVersioning/double-fp-type.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2024 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
;
; REQUIRES: llvm-14-plus
; RUN: igc_opt --opaque-pointers -debugify -igc-custom-loop-opt -S < %s 2>&1 | FileCheck %s
; ------------------------------------------------
; CustomLoopVersioning
; ------------------------------------------------

; This test checks that we're not creating a cmp inst with mismatched fp types.

define spir_kernel void @test_customloop(ptr addrspace(65549) %a, double %b, double %c, double %d) {
entry:
%aa = inttoptr i32 42 to ptr addrspace(65549)
%cc = call double @llvm.maxnum.f64(double %c, double 3.000000e+00)
%dd = call double @llvm.minnum.f64(double %d, double 2.000000e+00)
br label %pre_header

pre_header:
; CHECK: [[TMP:%.*]] = load double
%0 = load double, ptr addrspace(65549) %aa, align 4
%1 = fmul double %b, %0
; CHECK: fcmp fast ogt double [[TMP]], 1.000000e+00
br label %loop_body

loop_body:
%2 = phi double [ %b, %pre_header ], [ %3, %loop_body ]
%3 = phi double [ %1, %pre_header ], [ %7, %loop_body ]
%4 = call double @llvm.maxnum.f64(double %cc, double %2)
%5 = call double @llvm.minnum.f64(double %dd, double %3)
%6 = load double, ptr addrspace(65549) %aa, align 4
%7 = fmul double %3, %6
%8 = fcmp ult double %3, %dd
br i1 %8, label %loop_body, label %end

end:
store double %3, ptr addrspace(65549) %a, align 4
ret void
}


declare double @llvm.maxnum.f64(double, double) #0
declare double @llvm.minnum.f64(double, double) #0

!igc.functions = !{!0}

!0 = !{ptr @test_customloop, !1}
!1 = !{!2}
!2 = !{!"function_type", i32 0}

0 comments on commit 44cc39b

Please sign in to comment.