[llvm-commits] [llvm] r62528 - in /llvm/trunk: lib/Support/APFloat.cpp test/CodeGen/X86/2009-01-19-fmod-constant-float.ll
Dale Johannesen
dalej at apple.com
Mon Jan 19 13:17:05 PST 2009
Author: johannes
Date: Mon Jan 19 15:17:05 2009
New Revision: 62528
URL: http://llvm.org/viewvc/llvm-project?rev=62528&view=rev
Log:
compile-time fmod was done incorrectly. PR 3316.
Added:
llvm/trunk/test/CodeGen/X86/2009-01-19-fmod-constant-float.ll
Modified:
llvm/trunk/lib/Support/APFloat.cpp
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=62528&r1=62527&r2=62528&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Mon Jan 19 15:17:05 2009
@@ -1531,7 +1531,7 @@
integerPart *x = new integerPart[parts];
bool ignored;
fs = V.convertToInteger(x, parts * integerPartWidth, true,
- rmNearestTiesToEven, &ignored);
+ rmTowardZero, &ignored);
if (fs==opInvalidOp)
return fs;
@@ -1811,7 +1811,9 @@
if (exponent < 0) {
/* Our absolute value is less than one; truncate everything. */
APInt::tcSet(parts, 0, dstPartsCount);
- truncatedBits = semantics->precision;
+ /* For exponent -1 the integer bit represents .5, look at that.
+ For smaller exponents leftmost truncated bit is 0. */
+ truncatedBits = semantics->precision -1U - exponent;
} else {
/* We want the most significant (exponent + 1) bits; the rest are
truncated. */
Added: llvm/trunk/test/CodeGen/X86/2009-01-19-fmod-constant-float.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2009-01-19-fmod-constant-float.ll?rev=62528&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2009-01-19-fmod-constant-float.ll (added)
+++ llvm/trunk/test/CodeGen/X86/2009-01-19-fmod-constant-float.ll Mon Jan 19 15:17:05 2009
@@ -0,0 +1,77 @@
+; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 1036831949 | count 2
+; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 3184315597 | count 2
+; check constant folding for 'frem'. PR 3316.
+
+; ModuleID = 'tt.c'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+define float @test1() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = call double @fmod(double 1.000000e-01, double 1.000000e+00) nounwind readonly ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+declare double @fmod(double, double) nounwind readonly
+
+define float @test2() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = call double @fmod(double -1.000000e-01, double 1.000000e+00) nounwind readonly ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+define float @test3() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = call double @fmod(double 1.000000e-01, double -1.000000e+00) nounwind readonly ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+define float @test4() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = call double @fmod(double -1.000000e-01, double -1.000000e+00) nounwind readonly ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
More information about the llvm-commits
mailing list