@@ -3186,6 +3186,56 @@ def CIR_AssumeOp : CIR_Op<"assume"> {
31863186 }];
31873187}
31883188
3189+ def CIR_AssumeAlignedOp : CIR_Op<"assume_aligned", [
3190+ Pure, AllTypesMatch<["pointer", "result"]>
3191+ ]> {
3192+ let summary = "Tell the optimizer that a pointer is aligned";
3193+ let description = [{
3194+ The `cir.assume_aligned` operation takes two or three arguments. The first
3195+ argument `pointer` gives the pointer value whose alignment is to be assumed,
3196+ and the second argument `align` is an integer attribute that gives the
3197+ assumed alignment.
3198+
3199+ The `offset` argument is optional. If given, it represents misalignment
3200+ offset. When it's present, this operation tells the optimizer that the
3201+ pointer is always misaligned to the alignment by `offset` bytes, a.k.a. the
3202+ pointer yielded by `(char *)pointer - offset` is aligned to the specified
3203+ alignment. Note that the `offset` argument is an SSA value rather than an
3204+ attribute, which means that you could pass a dynamically determined value
3205+ as the mialignment offset.
3206+
3207+ The result of this operation has the same value as the `pointer` argument,
3208+ but it additionally carries any alignment information indicated by this
3209+ operation.
3210+
3211+ This operation corresponds to the `__builtin_assume_aligned` builtin
3212+ function.
3213+
3214+ Example:
3215+
3216+ ```mlir
3217+ // Assume that %0 is a CIR pointer value of type !cir.ptr<!s32i>
3218+ %1 = cir.assume_aligned %0 alignment 16 : !cir.ptr<!s32i>
3219+
3220+ // With a misalignment offset of 4 bytes:
3221+ %2 = cir.const #cir.int<4> : !u64i
3222+ %3 = cir.assume_aligned %0 alignment 16 [offset %2 : !u64i] : !cir.ptr<!s32i>
3223+ ```
3224+ }];
3225+
3226+ let arguments = (ins CIR_PointerType:$pointer,
3227+ I64Attr:$alignment,
3228+ Optional<CIR_IntType>:$offset);
3229+ let results = (outs CIR_PointerType:$result);
3230+
3231+ let assemblyFormat = [{
3232+ $pointer
3233+ `alignment` $alignment
3234+ (`[` `offset` $offset^ `:` type($offset) `]`)?
3235+ `:` qualified(type($pointer)) attr-dict
3236+ }];
3237+ }
3238+
31893239def CIR_AssumeSepStorageOp : CIR_Op<"assume_separate_storage", [
31903240 SameTypeOperands
31913241]> {
0 commit comments