[clang] cdc1f8a - [CIR] Match codegen change on fmin and fmax
Michael Liao via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 11 09:03:57 PST 2026
Author: Michael Liao
Date: 2026-02-11T12:03:40-05:00
New Revision: cdc1f8afe846cc6c42e2d7812ce9e4c98a4a4d7f
URL: https://github.com/llvm/llvm-project/commit/cdc1f8afe846cc6c42e2d7812ce9e4c98a4a4d7f
DIFF: https://github.com/llvm/llvm-project/commit/cdc1f8afe846cc6c42e2d7812ce9e4c98a4a4d7f.diff
LOG: [CIR] Match codegen change on fmin and fmax
- #113133 adds 'nsz' on the emitted 'llvm.minmum'/'llvm.maxnum' from
fmin/fmax following the semantic clarification from #112852.
Added:
Modified:
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/test/CIR/CodeGen/builtin-floating-point.c
Removed:
################################################################################
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 32815ee5e10ab..81f5d5ac6673b 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1669,8 +1669,9 @@ mlir::LogicalResult CIRToLLVMFMaxNumOpLowering::matchAndRewrite(
cir::FMaxNumOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type resTy = typeConverter->convertType(op.getType());
- rewriter.replaceOpWithNewOp<mlir::LLVM::MaxNumOp>(op, resTy, adaptor.getLhs(),
- adaptor.getRhs());
+ rewriter.replaceOpWithNewOp<mlir::LLVM::MaxNumOp>(
+ op, resTy, adaptor.getLhs(), adaptor.getRhs(),
+ mlir::LLVM::FastmathFlags::nsz);
return mlir::success();
}
@@ -1678,8 +1679,9 @@ mlir::LogicalResult CIRToLLVMFMinNumOpLowering::matchAndRewrite(
cir::FMinNumOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type resTy = typeConverter->convertType(op.getType());
- rewriter.replaceOpWithNewOp<mlir::LLVM::MinNumOp>(op, resTy, adaptor.getLhs(),
- adaptor.getRhs());
+ rewriter.replaceOpWithNewOp<mlir::LLVM::MinNumOp>(
+ op, resTy, adaptor.getLhs(), adaptor.getRhs(),
+ mlir::LLVM::FastmathFlags::nsz);
return mlir::success();
}
diff --git a/clang/test/CIR/CodeGen/builtin-floating-point.c b/clang/test/CIR/CodeGen/builtin-floating-point.c
index 4a331c73f0248..00d53d600dcc8 100644
--- a/clang/test/CIR/CodeGen/builtin-floating-point.c
+++ b/clang/test/CIR/CodeGen/builtin-floating-point.c
@@ -1735,11 +1735,11 @@ float my_fmaxf(float x, float y) {
// CHECK: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.float
// LLVM: define dso_local float @my_fmaxf
- // LLVM: %{{.+}} = call float @llvm.maxnum.f32(float %{{.+}}, float %{{.+}})
+ // LLVM: %{{.+}} = call nsz float @llvm.maxnum.f32(float %{{.+}}, float %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fmaxf(
- // OGCG: call float @llvm.maxnum.f32(
+ // OGCG: call nsz float @llvm.maxnum.f32(
}
double my_fmax(double x, double y) {
@@ -1748,11 +1748,11 @@ double my_fmax(double x, double y) {
// CHECK: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.double
// LLVM: define dso_local double @my_fmax
- // LLVM: %{{.+}} = call double @llvm.maxnum.f64(double %{{.+}}, double %{{.+}})
+ // LLVM: %{{.+}} = call nsz double @llvm.maxnum.f64(double %{{.+}}, double %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fmax(
- // OGCG: call double @llvm.maxnum.f64(
+ // OGCG: call nsz double @llvm.maxnum.f64(
}
long double my_fmaxl(long double x, long double y) {
@@ -1762,11 +1762,11 @@ long double my_fmaxl(long double x, long double y) {
// AARCH64: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.long_double<!cir.double>
// LLVM: define dso_local x86_fp80 @my_fmaxl
- // LLVM: %{{.+}} = call x86_fp80 @llvm.maxnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
+ // LLVM: %{{.+}} = call nsz x86_fp80 @llvm.maxnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fmaxl(
- // OGCG: call x86_fp80 @llvm.maxnum.f80(
+ // OGCG: call nsz x86_fp80 @llvm.maxnum.f80(
}
float fmaxf(float, float);
@@ -1779,11 +1779,11 @@ float call_fmaxf(float x, float y) {
// CHECK: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.float
// LLVM: define dso_local float @call_fmaxf
- // LLVM: %{{.+}} = call float @llvm.maxnum.f32(float %{{.+}}, float %{{.+}})
+ // LLVM: %{{.+}} = call nsz float @llvm.maxnum.f32(float %{{.+}}, float %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fmaxf(
- // OGCG: call float @llvm.maxnum.f32(
+ // OGCG: call nsz float @llvm.maxnum.f32(
}
double call_fmax(double x, double y) {
@@ -1792,11 +1792,11 @@ double call_fmax(double x, double y) {
// CHECK: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.double
// LLVM: define dso_local double @call_fmax
- // LLVM: %{{.+}} = call double @llvm.maxnum.f64(double %{{.+}}, double %{{.+}})
+ // LLVM: %{{.+}} = call nsz double @llvm.maxnum.f64(double %{{.+}}, double %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fmax(
- // OGCG: call double @llvm.maxnum.f64(
+ // OGCG: call nsz double @llvm.maxnum.f64(
}
long double call_fmaxl(long double x, long double y) {
@@ -1806,11 +1806,11 @@ long double call_fmaxl(long double x, long double y) {
// AARCH64: %{{.+}} = cir.fmaxnum %{{.+}}, %{{.+}} : !cir.long_double<!cir.double>
// LLVM: define dso_local x86_fp80 @call_fmaxl
- // LLVM: %{{.+}} = call x86_fp80 @llvm.maxnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
+ // LLVM: %{{.+}} = call nsz x86_fp80 @llvm.maxnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fmaxl(
- // OGCG: call x86_fp80 @llvm.maxnum.f80(
+ // OGCG: call nsz x86_fp80 @llvm.maxnum.f80(
}
// fmin
@@ -1821,11 +1821,11 @@ float my_fminf(float x, float y) {
// CHECK: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.float
// LLVM: define dso_local float @my_fminf
- // LLVM: %{{.+}} = call float @llvm.minnum.f32(float %{{.+}}, float %{{.+}})
+ // LLVM: %{{.+}} = call nsz float @llvm.minnum.f32(float %{{.+}}, float %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fminf(
- // OGCG: call float @llvm.minnum.f32(
+ // OGCG: call nsz float @llvm.minnum.f32(
}
double my_fmin(double x, double y) {
@@ -1834,11 +1834,11 @@ double my_fmin(double x, double y) {
// CHECK: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.double
// LLVM: define dso_local double @my_fmin
- // LLVM: %{{.+}} = call double @llvm.minnum.f64(double %{{.+}}, double %{{.+}})
+ // LLVM: %{{.+}} = call nsz double @llvm.minnum.f64(double %{{.+}}, double %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fmin(
- // OGCG: call double @llvm.minnum.f64(
+ // OGCG: call nsz double @llvm.minnum.f64(
}
long double my_fminl(long double x, long double y) {
@@ -1848,11 +1848,11 @@ long double my_fminl(long double x, long double y) {
// AARCH64: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.long_double<!cir.double>
// LLVM: define dso_local x86_fp80 @my_fminl
- // LLVM: %{{.+}} = call x86_fp80 @llvm.minnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
+ // LLVM: %{{.+}} = call nsz x86_fp80 @llvm.minnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@my_fminl(
- // OGCG: call x86_fp80 @llvm.minnum.f80(
+ // OGCG: call nsz x86_fp80 @llvm.minnum.f80(
}
float fminf(float, float);
@@ -1865,11 +1865,11 @@ float call_fminf(float x, float y) {
// CHECK: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.float
// LLVM: define dso_local float @call_fminf
- // LLVM: %{{.+}} = call float @llvm.minnum.f32(float %{{.+}}, float %{{.+}})
+ // LLVM: %{{.+}} = call nsz float @llvm.minnum.f32(float %{{.+}}, float %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fminf(
- // OGCG: call float @llvm.minnum.f32(
+ // OGCG: call nsz float @llvm.minnum.f32(
}
double call_fmin(double x, double y) {
@@ -1878,11 +1878,11 @@ double call_fmin(double x, double y) {
// CHECK: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.double
// LLVM: define dso_local double @call_fmin
- // LLVM: %{{.+}} = call double @llvm.minnum.f64(double %{{.+}}, double %{{.+}})
+ // LLVM: %{{.+}} = call nsz double @llvm.minnum.f64(double %{{.+}}, double %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fmin(
- // OGCG: call double @llvm.minnum.f64(
+ // OGCG: call nsz double @llvm.minnum.f64(
}
long double call_fminl(long double x, long double y) {
@@ -1892,11 +1892,11 @@ long double call_fminl(long double x, long double y) {
// AARCH64: %{{.+}} = cir.fminnum %{{.+}}, %{{.+}} : !cir.long_double<!cir.double>
// LLVM: define dso_local x86_fp80 @call_fminl
- // LLVM: %{{.+}} = call x86_fp80 @llvm.minnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
+ // LLVM: %{{.+}} = call nsz x86_fp80 @llvm.minnum.f80(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
// LLVM: }
// OGCG: define{{.*}}@call_fminl(
- // OGCG: call x86_fp80 @llvm.minnum.f80(
+ // OGCG: call nsz x86_fp80 @llvm.minnum.f80(
}
// fmod
More information about the cfe-commits
mailing list