Skip to content

Commit 5286dff

Browse files
committed
[SYCL][ESIMD] Fix LowerESIMD crash on a scalar fptoui.
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent bd0edfe commit 5286dff

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

llvm/lib/SYCLLowerIR/LowerESIMD.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,11 @@ PreservedAnalyses SYCLLowerESIMDPass::run(Function &F,
12391239
if (auto CastOp = dyn_cast<llvm::CastInst>(&I)) {
12401240
llvm::Type *DstTy = CastOp->getDestTy();
12411241
auto CastOpcode = CastOp->getOpcode();
1242-
if ((CastOpcode == llvm::Instruction::FPToUI &&
1243-
DstTy->getScalarType()->getPrimitiveSizeInBits() <= 32) ||
1244-
(CastOpcode == llvm::Instruction::FPToSI &&
1245-
DstTy->getScalarType()->getPrimitiveSizeInBits() < 32)) {
1242+
if (isa<FixedVectorType>(DstTy) &&
1243+
((CastOpcode == llvm::Instruction::FPToUI &&
1244+
DstTy->getScalarType()->getPrimitiveSizeInBits() <= 32) ||
1245+
(CastOpcode == llvm::Instruction::FPToSI &&
1246+
DstTy->getScalarType()->getPrimitiveSizeInBits() < 32))) {
12461247
IRBuilder<> Builder(&I);
12471248
llvm::Value *Src = CastOp->getOperand(0);
12481249
auto TmpTy = llvm::FixedVectorType::get(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; This is a regression test for LowerESIMD crashing on a scalar fptoui
2+
; instruction.
3+
;
4+
; RUN: opt < %s -LowerESIMD -S | FileCheck %s
5+
6+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
7+
target triple = "spir64-unknown-unknown-sycldevice"
8+
9+
; Function Attrs: convergent norecurse
10+
define dso_local spir_func i32 @foo(float %x) !sycl_explicit_simd !1 {
11+
%y = fptoui float %x to i32
12+
; check that the scalar float to unsigned int conversion is left intact
13+
; CHECK: %y = fptoui float %x to i32
14+
ret i32 %y
15+
}
16+
17+
!1 = !{i32 0, i32 0}

0 commit comments

Comments
 (0)