https://github.com/Siya-05 created https://github.com/llvm/llvm-project/pull/237558
Part of #227917 ## Summary - Fix conflicting `llvm.zeroext` and `llvm.signext` result attributes in `updateResAttrs()`. - Add regression tests for signed/unsigned returns and call results. ## Testing - Regression test: PASS (1/1). - Broader ABI-lowering suite: 17 failures due to a local `cir-translate` option mismatch. >From 9d652922a1d67fac8966a0c85ccd3fde89c42cf3 Mon Sep 17 00:00:00 2001 From: Sivapriya <[email protected]> Date: Sat, 31 Oct 2026 06:42:58 +0000 Subject: [PATCH] [CIR] Avoid duplicate ABI result extension attributes --- .../TargetLowering/CIRABIRewriteContext.cpp | 4 +- .../extend-return-existing-attrs.cir | 68 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 clang/test/CIR/Transforms/abi-lowering/extend-return-existing-attrs.cir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp index c85f5421c21050..92c259bf7b34cb 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp @@ -326,9 +326,11 @@ mlir::ArrayAttr updateResAttrs(mlir::MLIRContext *ctx, if (existingResAttrs && !existingResAttrs.empty()) attrs.append( mlir::cast<mlir::DictionaryAttr>(existingResAttrs[0]).getValue()); - if (retInfo.kind == ArgKind::Extend) + if (retInfo.kind == ArgKind::Extend) { + attrs.erase(retInfo.signExtend ? "llvm.zeroext" : "llvm.signext"); attrs.set(retInfo.signExtend ? "llvm.signext" : "llvm.zeroext", mlir::UnitAttr::get(ctx)); + } if (needsNoUndefDrop) attrs.erase(mlir::LLVM::LLVMDialect::getNoUndefAttrName()); return mlir::ArrayAttr::get(ctx, {attrs.getDictionary(ctx)}); diff --git a/clang/test/CIR/Transforms/abi-lowering/extend-return-existing-attrs.cir b/clang/test/CIR/Transforms/abi-lowering/extend-return-existing-attrs.cir new file mode 100644 index 00000000000000..6b8ed6d284eb9c --- /dev/null +++ b/clang/test/CIR/Transforms/abi-lowering/extend-return-existing-attrs.cir @@ -0,0 +1,68 @@ + +// RUN: cir-opt %s -cir-call-conv-lowering="classification-attr=test_classify" \ +// RUN: | FileCheck %s + +!s8i = !cir.int<s, 8> +!u8i = !cir.int<u, 8> + +#extend_signed_return = { + return = { kind = "extend", + coerced_type = !cir.int<s, 32>, + sign_extend = true }, + args = [ ] +} + +#extend_unsigned_return = { + return = { kind = "extend", + coerced_type = !cir.int<u, 32>, + sign_extend = false }, + args = [ ] +} + +module attributes { + dlti.dl_spec = #dlti.dl_spec< + #dlti.dl_entry<i8, dense<8>: vector<2xi64>>, + #dlti.dl_entry<i32, dense<32>: vector<2xi64>>> +} { + // An existing zeroext must be replaced with signext. + cir.func @returns_s8() -> (!s8i {llvm.zeroext}) + attributes { test_classify = #extend_signed_return } { + %0 = cir.const #cir.int<7> : !s8i + cir.return %0 : !s8i + } + + // CHECK: cir.func{{.*}} @returns_s8() -> (!s8i {llvm.signext}) + // CHECK: cir.return %{{.*}} : !s8i + + // Check both the caller's result and the call result. + cir.func @caller_s8() -> (!s8i {llvm.zeroext}) + attributes { test_classify = #extend_signed_return } { + %0 = cir.call @returns_s8() : () -> (!s8i {llvm.zeroext}) + cir.return %0 : !s8i + } + + // CHECK: cir.func{{.*}} @caller_s8() -> (!s8i {llvm.signext}) + // CHECK: %[[SR:.*]] = cir.call @returns_s8() : () -> (!s8i {llvm.signext}) + // CHECK: cir.return %[[SR]] : !s8i + + // An existing signext must be replaced with zeroext. + cir.func @returns_u8() -> (!u8i {llvm.signext}) + attributes { test_classify = #extend_unsigned_return } { + %0 = cir.const #cir.int<7> : !u8i + cir.return %0 : !u8i + } + + // CHECK: cir.func{{.*}} @returns_u8() -> (!u8i {llvm.zeroext}) + // CHECK: cir.return %{{.*}} : !u8i + + // Check both the caller's result and the call result. + cir.func @caller_u8() -> (!u8i {llvm.signext}) + attributes { test_classify = #extend_unsigned_return } { + %0 = cir.call @returns_u8() : () -> (!u8i {llvm.signext}) + cir.return %0 : !u8i + } + + // CHECK: cir.func{{.*}} @caller_u8() -> (!u8i {llvm.zeroext}) + // CHECK: %[[UR:.*]] = cir.call @returns_u8() : () -> (!u8i {llvm.zeroext}) + // CHECK: cir.return %[[UR]] : !u8i +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
