Bug 30698

Summary: Build fails when building for device using --aot-options=-O=float32 and performing a calculation on float or nfloat variables
Product: iOS Reporter: Jon Goldberger [MSFT] <jon.goldberger>
Component: ToolsAssignee: Zoltan Varga <vargaz>
Severity: normal CC: mohitk, mono-bugs+monodevelop, mono-bugs+monotouch, morgan, sebastien
Priority: ---    
Version: XI 8.10   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Jon Goldberger [MSFT] 2015-06-02 22:35:14 UTC
## Description

When setting --aot-options=-O=float32 as noted in our Advanced Topics guide for Floating Point [1], and then performing a calculation on two float or nfloat variables, the build fails with the following error message:

>/Users/apple/Downloads/TestAotOptions/TestAotOptions/MTOUCH: Error MT3001: Could not AOT the assembly '/Users/apple/Downloads/TestAotOptions/TestAotOptions/obj/iPhone/Debug/mtouch-cache/32/Build/Xamarin.iOS.dll' (MT3001) (TestAotOptions)

and the following in the build output:

>Mono Ahead of Time compiler - compiling assembly /Users/apple/Downloads/TestAotOptions/TestAotOptions/obj/iPhone/Debug/mtouch-cache/32/Build/Xamarin.iOS.dll
>		unknown opcode r4_rem in mono_arch_output_basic_block()
>		* Assertion: should not be reached at ../../../../../mono/mono/mini/mini-arm.c:5884
>		AOT Compilation exited with code 134, command:
>		MONO_PATH=/Users/apple/Downloads/TestAotOptions/TestAotOptions/obj/iPhone/Debug/mtouch-cache/32/Build /Library/Frameworks/Xamarin.iOS.framework/Versions/ --debug -O=gsharedvt -O=float32  --aot=mtriple=armv7-ios,full,static,asmonly,direct-icalls,dwarfdebug,no-direct-calls,iphone-abi,outfile=/Users/apple/Downloads/TestAotOptions/TestAotOptions/obj/iPhone/Debug/mtouch-cache/Xamarin.iOS.dll.armv7.s "/Users/apple/Downloads/TestAotOptions/TestAotOptions/obj/iPhone/Debug/mtouch-cache/32/Build/Xamarin.iOS.dll"

## Steps to reproduce

1. Create a new Single View Xamarin iOS Unified API app project.

2. Add --aot-options=-O=float32 to the "Additional touch arguments" for Debug iPhone configuration.

3. Add the following code to the AppDelegate Finished Launching method:

>float x = 1.0f;
>float y = 1.0f;
>float z = x % y;
>System.Console.WriteLine("{0}", z);

4. Launch the project to an iOS device.

Expected result: App will build and launch.

Actual result: Build failed with above noted errors. 

## Notes

Tried using nfloat instead of float but this had no effect. 

## My environment

=== Xamarin Studio ===

Version 5.9.2 (build 4)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509020004
Git revision: 288eb01e990f2d93b856c9600a0c40708b930128
Build date: 2015-06-01 14:29:52-04
Xamarin addins: c12ed369b0e05dc5c35c9350fdcbc00a46c0ff99

=== Operating System ===

Mac OS X 10.10.3
Darwin Jons-iMac.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 2 Zoltan Varga 2015-06-03 14:41:51 UTC
Fixed in mono master 550a8017ec225f016a81f6e37ecfcf97e94395f6.
Comment 3 Zoltan Varga 2015-06-03 14:42:09 UTC
This could be a candidate for sr2/3.
Comment 4 Morgan 2015-06-03 14:43:44 UTC
Can you guys update this ticket when the fix goes live? 

We're nearing release of a product, and this should give us improved performance. We'd like to use it ASAP.
Comment 5 Zoltan Varga 2015-06-03 14:54:55 UTC
A workaround is to avoid doing floating point remainder operations in c# code, they are emulated even in C (fmod), so they are never going to be fast.
Comment 9 Mohit Kheterpal 2015-06-04 10:33:21 UTC
I have checked this issue with monotouch-  and observed that this issue working fine after following steps mentioned in bug description as shown in screencast : http://www.screencast.com/t/x9PeRVlV

Hence closing this issue