https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/228004
Align with classic codegen, which emits add nsw and fcmp one >From 33d26b692626fe810786ff1d76d19c272a7c3cc0 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy <[email protected]> Date: Thu, 1 Oct 2026 11:11:14 +0200 Subject: [PATCH] [CIR][AMDGPU] Use nsw add and ordered compare in logb lowering Align with classic codegen, which emits add nsw and fcmp one --- clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp | 4 ++-- clang/test/CIR/CodeGenHIP/builtins-amdgcn-logb-scalbn.hip | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp index b2aac0d376fa1..e0fc28f278d1b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp @@ -89,7 +89,7 @@ static mlir::Value emitLogbBuiltin(CIRGenFunction &cgf, const CallExpr *e, mlir::Value negativeOne = builder.getConstant(loc, cir::IntAttr::get(int32Ty, -1)); - mlir::Value expMinus1 = builder.createAdd(loc, exp, negativeOne); + mlir::Value expMinus1 = builder.createNSWAdd(loc, exp, negativeOne); mlir::Value siToFp = cir::CastOp::create( builder, loc, srcTy, cir::CastKind::int_to_float, expMinus1); @@ -100,7 +100,7 @@ static mlir::Value emitLogbBuiltin(CIRGenFunction &cgf, const CallExpr *e, mlir::Value inf = builder.getConstant(loc, cir::FPAttr::get(srcTy, infVal)); mlir::Value fabsNegInf = - builder.createCompare(loc, cir::CmpOpKind::ne, fabs, inf); + builder.createCompare(loc, cir::CmpOpKind::one, fabs, inf); mlir::Value sel = builder.createSelect(loc, fabsNegInf, siToFp, fabs); diff --git a/clang/test/CIR/CodeGenHIP/builtins-amdgcn-logb-scalbn.hip b/clang/test/CIR/CodeGenHIP/builtins-amdgcn-logb-scalbn.hip index b4d28a8bb7487..d5f31ff5cf019 100644 --- a/clang/test/CIR/CodeGenHIP/builtins-amdgcn-logb-scalbn.hip +++ b/clang/test/CIR/CodeGenHIP/builtins-amdgcn-logb-scalbn.hip @@ -17,6 +17,8 @@ // CIR: cir.call_llvm_intrinsic "frexp" {{.*}} : (!cir.float) -> {{.*}} // LLVM: define{{.*}} float @_Z11test_logbfff( // LLVM: call { float, i32 } @llvm.frexp.f32.i32(float {{.*}}) +// LLVM: add nsw i32 %{{.*}}, -1 +// LLVM: fcmp{{.*}} one float %{{.*}}, +inf __device__ float test_logbff(float a) { return __builtin_logbf(a); } @@ -25,6 +27,8 @@ __device__ float test_logbff(float a) { // CIR: cir.call_llvm_intrinsic "frexp" {{.*}} : (!cir.double) -> {{.*}} // LLVM: define{{.*}} double @_Z11test_logbddd( // LLVM: call { double, i32 } @llvm.frexp.f64.i32(double {{.*}}) +// LLVM: add nsw i32 %{{.*}}, -1 +// LLVM: fcmp{{.*}} one double %{{.*}}, +inf __device__ double test_logbdd(double a) { return __builtin_logb(a); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
