Skip to content

Commit bf3a042

Browse files
committed
fixup! [CIR][LowerToLLVM] Fix crash in PtrStrideOp lowering
I'm not sure how this was working before, but the stride can also be a block argument and not have a defining op, so we also need to account for that. Fixes #912
1 parent b625535 commit bf3a042

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ class CIRPtrStrideOpLowering
591591
// before it. To achieve that, look at unary minus, which already got
592592
// lowered to "sub 0, x".
593593
auto sub = dyn_cast<mlir::LLVM::SubOp>(indexOp);
594-
auto unary =
595-
dyn_cast<mlir::cir::UnaryOp>(ptrStrideOp.getStride().getDefiningOp());
594+
auto unary = dyn_cast_if_present<mlir::cir::UnaryOp>(
595+
ptrStrideOp.getStride().getDefiningOp());
596596
bool rewriteSub =
597597
unary && unary.getKind() == mlir::cir::UnaryOpKind::Minus && sub;
598598
if (rewriteSub)

clang/test/CIR/Lowering/ptrstride.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: cir-opt %s -cir-to-llvm -o %t.mlir
22
// RUN: FileCheck %s --input-file=%t.mlir -check-prefix=MLIR
3-
// XFAIL:*
43

54
!s32i = !cir.int<s, 32>
65
module {
@@ -31,4 +30,5 @@ module {
3130
// MLIR: llvm.return
3231

3332
// MLIR-LABEL: @g
34-
// MLIR: llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i32) -> !llvm.ptr, i32
33+
// MLIR: %0 = llvm.sext %arg1 : i32 to i64
34+
// MLIR-NEXT: llvm.getelementptr %arg0[%0] : (!llvm.ptr, i64) -> !llvm.ptr, i32

0 commit comments

Comments
 (0)