@@ -3143,6 +3143,56 @@ def CIR_AssumeOp : CIR_Op<"assume"> {
31433143 }];
31443144}
31453145
3146+ def CIR_AssumeAlignedOp : CIR_Op<"assume_aligned", [
3147+ Pure, AllTypesMatch<["pointer", "result"]>
3148+ ]> {
3149+ let summary = "Tell the optimizer that a pointer is aligned";
3150+ let description = [{
3151+ The `cir.assume_aligned` operation takes two or three arguments. The first
3152+ argument `pointer` gives the pointer value whose alignment is to be assumed,
3153+ and the second argument `align` is an integer attribute that gives the
3154+ assumed alignment.
3155+
3156+ The `offset` argument is optional. If given, it represents misalignment
3157+ offset. When it's present, this operation tells the optimizer that the
3158+ pointer is always misaligned to the alignment by `offset` bytes, a.k.a. the
3159+ pointer yielded by `(char *)pointer - offset` is aligned to the specified
3160+ alignment. Note that the `offset` argument is an SSA value rather than an
3161+ attribute, which means that you could pass a dynamically determined value
3162+ as the mialignment offset.
3163+
3164+ The result of this operation has the same value as the `pointer` argument,
3165+ but it additionally carries any alignment information indicated by this
3166+ operation.
3167+
3168+ This operation corresponds to the `__builtin_assume_aligned` builtin
3169+ function.
3170+
3171+ Example:
3172+
3173+ ```mlir
3174+ // Assume that %0 is a CIR pointer value of type !cir.ptr<!s32i>
3175+ %1 = cir.assume_aligned %0 alignment 16 : !cir.ptr<!s32i>
3176+
3177+ // With a misalignment offset of 4 bytes:
3178+ %2 = cir.const #cir.int<4> : !u64i
3179+ %3 = cir.assume_aligned %0 alignment 16 [offset %2 : !u64i] : !cir.ptr<!s32i>
3180+ ```
3181+ }];
3182+
3183+ let arguments = (ins CIR_PointerType:$pointer,
3184+ I64Attr:$alignment,
3185+ Optional<CIR_IntType>:$offset);
3186+ let results = (outs CIR_PointerType:$result);
3187+
3188+ let assemblyFormat = [{
3189+ $pointer
3190+ `alignment` $alignment
3191+ (`[` `offset` $offset^ `:` type($offset) `]`)?
3192+ `:` qualified(type($pointer)) attr-dict
3193+ }];
3194+ }
3195+
31463196def CIR_AssumeSepStorageOp : CIR_Op<"assume_separate_storage", [
31473197 SameTypeOperands
31483198]> {
0 commit comments