Skip to content

Commit d595fc9

Browse files
authored
Revert "[clang] Lower modf builtin using llvm.modf intrinsic" (#127987)
Reverts #126750 Revering while I investigate: https://lab.llvm.org/buildbot/#/builders/72/builds/8406
1 parent dc326d0 commit d595fc9

File tree

6 files changed

+20
-70
lines changed

6 files changed

+20
-70
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -859,24 +859,6 @@ static void emitSincosBuiltin(CodeGenFunction &CGF, const CallExpr *E,
859859
StoreCos->setMetadata(LLVMContext::MD_noalias, AliasScopeList);
860860
}
861861

862-
static llvm::Value *emitModfBuiltin(CodeGenFunction &CGF, const CallExpr *E,
863-
llvm::Intrinsic::ID IntrinsicID) {
864-
llvm::Value *Val = CGF.EmitScalarExpr(E->getArg(0));
865-
llvm::Value *IntPartDest = CGF.EmitScalarExpr(E->getArg(1));
866-
867-
llvm::Value *Call =
868-
CGF.Builder.CreateIntrinsic(IntrinsicID, {Val->getType()}, Val);
869-
870-
llvm::Value *FractionalResult = CGF.Builder.CreateExtractValue(Call, 0);
871-
llvm::Value *IntegralResult = CGF.Builder.CreateExtractValue(Call, 1);
872-
873-
QualType DestPtrType = E->getArg(1)->getType()->getPointeeType();
874-
LValue IntegralLV = CGF.MakeNaturalAlignAddrLValue(IntPartDest, DestPtrType);
875-
CGF.EmitStoreOfScalar(IntegralResult, IntegralLV);
876-
877-
return FractionalResult;
878-
}
879-
880862
/// EmitFAbs - Emit a call to @llvm.fabs().
881863
static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) {
882864
Function *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType());
@@ -4130,15 +4112,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41304112
case Builtin::BI__builtin_frexpf128:
41314113
case Builtin::BI__builtin_frexpf16:
41324114
return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp));
4133-
case Builtin::BImodf:
4134-
case Builtin::BImodff:
4135-
case Builtin::BImodfl:
4136-
case Builtin::BI__builtin_modf:
4137-
case Builtin::BI__builtin_modff:
4138-
case Builtin::BI__builtin_modfl:
4139-
if (Builder.getIsFPConstrained())
4140-
break; // TODO: Emit constrained modf intrinsic once one exists.
4141-
return RValue::get(emitModfBuiltin(*this, E, Intrinsic::modf));
41424115
case Builtin::BI__builtin_isgreater:
41434116
case Builtin::BI__builtin_isgreaterequal:
41444117
case Builtin::BI__builtin_isless:

clang/test/CodeGen/X86/math-builtins.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,6 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {
3838
// NO__ERRNO-NEXT: [[FREXP_F128_0:%.+]] = extractvalue { fp128, i32 } [[FREXP_F128]], 0
3939

4040

41-
// NO__ERRNO: [[MODF_F64:%.+]] = call { double, double } @llvm.modf.f64(double %{{.+}})
42-
// NO__ERRNO-NEXT: [[MODF_F64_FP:%.+]] = extractvalue { double, double } [[MODF_F64]], 0
43-
// NO__ERRNO-NEXT: [[MODF_F64_IP:%.+]] = extractvalue { double, double } [[MODF_F64]], 1
44-
// NO__ERRNO-NEXT: store double [[MODF_F64_IP]], ptr %{{.+}}, align 8
45-
46-
// NO__ERRNO: [[MODF_F32:%.+]] = call { float, float } @llvm.modf.f32(float %{{.+}})
47-
// NO__ERRNO-NEXT: [[MODF_F32_FP:%.+]] = extractvalue { float, float } [[MODF_F32]], 0
48-
// NO__ERRNO-NEXT: [[MODF_F32_IP:%.+]] = extractvalue { float, float } [[MODF_F32]], 1
49-
// NO__ERRNO-NEXT: store float [[MODF_F32_IP]], ptr %{{.+}}, align 4
50-
51-
// NO__ERRNO: [[MODF_F80:%.+]] = call { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80 %{{.+}})
52-
// NO__ERRNO-NEXT: [[MODF_F80_FP:%.+]] = extractvalue { x86_fp80, x86_fp80 } [[MODF_F80]], 0
53-
// NO__ERRNO-NEXT: [[MODF_F80_IP:%.+]] = extractvalue { x86_fp80, x86_fp80 } [[MODF_F80]], 1
54-
// NO__ERRNO-NEXT: store x86_fp80 [[MODF_F80_IP]], ptr %{{.+}}, align 16
55-
56-
// NO__ERRNO: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
57-
58-
5941
// NO__ERRNO: [[SINCOS_F64:%.+]] = call { double, double } @llvm.sincos.f64(double %{{.+}})
6042
// NO__ERRNO-NEXT: [[SINCOS_F64_0:%.+]] = extractvalue { double, double } [[SINCOS_F64]], 0
6143
// NO__ERRNO-NEXT: [[SINCOS_F64_1:%.+]] = extractvalue { double, double } [[SINCOS_F64]], 1
@@ -157,13 +139,13 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {
157139

158140
__builtin_modf(f,d); __builtin_modff(f,fp); __builtin_modfl(f,l); __builtin_modff128(f,l);
159141

160-
// NO__ERRNO: declare { double, double } @llvm.modf.f64(double) [[READNONE_INTRINSIC]]
161-
// NO__ERRNO: declare { float, float } @llvm.modf.f32(float) [[READNONE_INTRINSIC]]
162-
// NO__ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80) [[READNONE_INTRINSIC]]
163-
// NO__ERRNO: declare fp128 @modff128(fp128 noundef, ptr noundef) [[NOT_READNONE:#[0-9]+]]
164-
// HAS_ERRNO: declare { double, double } @llvm.modf.f64(double) [[READNONE_INTRINSIC]]
165-
// HAS_ERRNO: declare { float, float } @llvm.modf.f32(float) [[READNONE_INTRINSIC]]
166-
// HAS_ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80) [[READNONE_INTRINSIC]]
142+
// NO__ERRNO: declare double @modf(double noundef, ptr noundef) [[NOT_READNONE:#[0-9]+]]
143+
// NO__ERRNO: declare float @modff(float noundef, ptr noundef) [[NOT_READNONE]]
144+
// NO__ERRNO: declare x86_fp80 @modfl(x86_fp80 noundef, ptr noundef) [[NOT_READNONE]]
145+
// NO__ERRNO: declare fp128 @modff128(fp128 noundef, ptr noundef) [[NOT_READNONE]]
146+
// HAS_ERRNO: declare double @modf(double noundef, ptr noundef) [[NOT_READNONE]]
147+
// HAS_ERRNO: declare float @modff(float noundef, ptr noundef) [[NOT_READNONE]]
148+
// HAS_ERRNO: declare x86_fp80 @modfl(x86_fp80 noundef, ptr noundef) [[NOT_READNONE]]
167149
// HAS_ERRNO: declare fp128 @modff128(fp128 noundef, ptr noundef) [[NOT_READNONE]]
168150

169151
__builtin_nan(c); __builtin_nanf(c); __builtin_nanl(c); __builtin_nanf128(c);

clang/test/CodeGen/aix-builtin-mapping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ int main()
1717
returnValue = __builtin_ldexpl(1.0L, 1);
1818
}
1919

20-
// CHECK: %{{.+}} = call { double, double } @llvm.modf.f64(double 1.000000e+00)
20+
// CHECK: %call = call double @modf(double noundef 1.000000e+00, ptr noundef %DummyLongDouble) #3
2121
// CHECK: %{{.+}} = call { double, i32 } @llvm.frexp.f64.i32(double 0.000000e+00)
2222
// CHECK: %{{.+}} = call double @llvm.ldexp.f64.i32(double 1.000000e+00, i32 1)

clang/test/CodeGen/builtin-attributes.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ char* f2(char* a, char* b) {
2424
return __builtin_strstr(a, b);
2525
}
2626

27-
// Note: Use asm label to disable intrinsic lowering of modf.
28-
double modf(double x, double*) asm("modf");
29-
float modff(float x, float*) asm("modff");
30-
long double modfl(long double x, long double*) asm("modfl");
31-
3227
// frexp is NOT readnone. It writes to its pointer argument.
3328
//
3429
// CHECK: f3
@@ -60,9 +55,9 @@ int f3(double x) {
6055
frexp(x, &e);
6156
frexpf(x, &e);
6257
frexpl(x, &e);
63-
modf(x, &e);
64-
modff(x, &e);
65-
modfl(x, &e);
58+
__builtin_modf(x, &e);
59+
__builtin_modff(x, &e);
60+
__builtin_modfl(x, &e);
6661
__builtin_remquo(x, x, &e);
6762
__builtin_remquof(x, x, &e);
6863
__builtin_remquol(x, x, &e);

clang/test/CodeGen/math-builtins-long.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ void foo(long double f, long double *l, int *i, const char *c) {
5858
// PPCF128: call fp128 @ldexpf128(fp128 noundef %{{.+}}, {{(signext)?.+}})
5959
__builtin_ldexpl(f,f);
6060

61-
// F80: call { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80 %{{.+}})
62-
// PPC: call { ppc_fp128, ppc_fp128 } @llvm.modf.ppcf128(ppc_fp128 %{{.+}})
63-
// X86F128: call { fp128, fp128 } @llvm.modf.f128(fp128 %{{.+}})
61+
// F80: call x86_fp80 @modfl(x86_fp80 noundef %{{.+}}, ptr noundef %{{.+}})
62+
// PPC: call ppc_fp128 @modfl(ppc_fp128 noundef %{{.+}}, ptr noundef %{{.+}})
63+
// X86F128: call fp128 @modfl(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
6464
// PPCF128: call fp128 @modff128(fp128 noundef %{{.+}}, ptr noundef %{{.+}})
6565
__builtin_modfl(f,l);
6666

clang/test/CodeGen/math-libcalls.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {
8383

8484
modf(f,d); modff(f,fp); modfl(f,l);
8585

86-
// NO__ERRNO: declare { double, double } @llvm.modf.f64(double) [[READNONE_INTRINSIC]]
87-
// NO__ERRNO: declare { float, float } @llvm.modf.f32(float) [[READNONE_INTRINSIC]]
88-
// NO__ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80) [[READNONE_INTRINSIC]]
89-
// HAS_ERRNO: declare { double, double } @llvm.modf.f64(double) [[READNONE_INTRINSIC]]
90-
// HAS_ERRNO: declare { float, float } @llvm.modf.f32(float) [[READNONE_INTRINSIC]]
91-
// HAS_ERRNO: declare { x86_fp80, x86_fp80 } @llvm.modf.f80(x86_fp80) [[READNONE_INTRINSIC]]
86+
// NO__ERRNO: declare double @modf(double noundef, ptr noundef) [[NOT_READNONE]]
87+
// NO__ERRNO: declare float @modff(float noundef, ptr noundef) [[NOT_READNONE]]
88+
// NO__ERRNO: declare x86_fp80 @modfl(x86_fp80 noundef, ptr noundef) [[NOT_READNONE]]
89+
// HAS_ERRNO: declare double @modf(double noundef, ptr noundef) [[NOT_READNONE]]
90+
// HAS_ERRNO: declare float @modff(float noundef, ptr noundef) [[NOT_READNONE]]
91+
// HAS_ERRNO: declare x86_fp80 @modfl(x86_fp80 noundef, ptr noundef) [[NOT_READNONE]]
9292
// HAS_MAYTRAP: declare double @modf(double noundef, ptr noundef) [[NOT_READNONE]]
9393
// HAS_MAYTRAP: declare float @modff(float noundef, ptr noundef) [[NOT_READNONE]]
9494
// HAS_MAYTRAP: declare x86_fp80 @modfl(x86_fp80 noundef, ptr noundef) [[NOT_READNONE]]

0 commit comments

Comments
 (0)