File tree 2 files changed +12
-5
lines changed
lib/CIR/Lowering/DirectToLLVM
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -499,21 +499,21 @@ class CIRPtrStrideOpLowering
499
499
// Zero-extend, sign-extend or trunc the pointer value.
500
500
auto index = adaptor.getStride ();
501
501
auto width = index .getType ().cast <mlir::IntegerType>().getWidth ();
502
- mlir::DataLayout LLVMLayout (
503
- index .getDefiningOp ()->getParentOfType <mlir::ModuleOp>());
502
+ mlir::DataLayout LLVMLayout (ptrStrideOp->getParentOfType <mlir::ModuleOp>());
504
503
auto layoutWidth =
505
504
LLVMLayout.getTypeIndexBitwidth (adaptor.getBase ().getType ());
506
- if (layoutWidth && width != *layoutWidth) {
505
+ auto indexOp = index .getDefiningOp ();
506
+ if (indexOp && layoutWidth && width != *layoutWidth) {
507
507
// If the index comes from a subtraction, make sure the extension happens
508
508
// before it. To achieve that, look at unary minus, which already got
509
509
// lowered to "sub 0, x".
510
- auto sub = dyn_cast<mlir::LLVM::SubOp>(index . getDefiningOp () );
510
+ auto sub = dyn_cast<mlir::LLVM::SubOp>(indexOp );
511
511
auto unary =
512
512
dyn_cast<mlir::cir::UnaryOp>(ptrStrideOp.getStride ().getDefiningOp ());
513
513
bool rewriteSub =
514
514
unary && unary.getKind () == mlir::cir::UnaryOpKind::Minus && sub;
515
515
if (rewriteSub)
516
- index = index . getDefiningOp () ->getOperand (1 );
516
+ index = indexOp ->getOperand (1 );
517
517
518
518
// Handle the cast
519
519
auto llvmDstType = mlir::IntegerType::get (ctx, *layoutWidth);
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ module {
12
12
%4 = cir.load %3 : !cir.ptr<!s32i>, !s32i
13
13
cir.return
14
14
}
15
+ cir.func @g(%arg0: !cir.ptr<!s32i>, %2 : !s32i) {
16
+ %3 = cir.ptr_stride(%arg0 : !cir.ptr<!s32i>, %2 : !s32i), !cir.ptr<!s32i>
17
+ cir.return
18
+ }
15
19
}
16
20
17
21
// MLIR-LABEL: @f
@@ -24,3 +28,6 @@ module {
24
28
// MLIR: %[[VAL_6:.*]] = llvm.getelementptr %[[VAL_3]]{{\[}}%[[VAL_5]]] : (!llvm.ptr, i64) -> !llvm.ptr, i32
25
29
// MLIR: %[[VAL_7:.*]] = llvm.load %[[VAL_6]] {alignment = 4 : i64} : !llvm.ptr -> i32
26
30
// MLIR: llvm.return
31
+
32
+ // MLIR-LABEL: @g
33
+ // MLIR: llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i32) -> !llvm.ptr, i32
You can’t perform that action at this time.
0 commit comments