[Xiaomi Mi 4i] shyamk:
And so I build a optimized cm 12.1 with linaro toolchain and -O3 flag. (from this thread http://xdaforums.com/mi-4i/development/wip-cyanogenmod-12-1-xiaomi-mi-4i-t3152134)

Standard CM disclaimers apply if you want to use this build

Steps :

1. Add this to your local manifest (make directory .repo/local_manifests under the source directory)

<?xml version="1.0" encoding="UTF-8"?>

<manifest>

<project path="kernel/xiaomi/ferrari" name="dh-harald/android_kernel_xiaomi_ferrari" />

<project path="device/xiaomi/ferrari" name="dh-harald/android_device_xiaomi_ferrari" />

<project path="vendor/xiaomi/ferrari" name="dh-harald/android_vendor_xiaomi_ferrari" />

<project path="device/qcom/common" name="CyanogenMod/android_device_qcom_common" />

<project path="external/mm-dash" name="CyanogenMod/android_external_mm-dash" />

<project path="hardware/qcom/fm" name="CyanogenMod/android_hardware_qcom_fm" />

</manifest>

Then execute the command "repo sync" to get the source code.

2. Execute the following commands (under the source directory) to get the linaro toolchain

git clone https://android.git.linaro.org/git-.../aarch64/aarch64-linux-android-4.9-linaro.git prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-linaro-4.9

git clone https://android-git.linaro.org/git-...x86/arm/arm-linux-androideabi-4.9-linaro.git/ prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-linaro-4.9

3. Make the following changes

diff --git a/core/clang/config.mk b/core/clang/config.mk

index 9c11797..67a545e 100644

--- a/core/clang/config.mk

+++ b/core/clang/config.mk

@@ -31,8 +31,8 @@ endif

# Clang flags for all host or target rules

CLANG_CONFIG_EXTRA_ASFLAGS :=

-CLANG_CONFIG_EXTRA_CFLAGS :=

-CLANG_CONFIG_EXTRA_CPPFLAGS :=

+CLANG_CONFIG_EXTRA_CFLAGS := -O3

+CLANG_CONFIG_EXTRA_CPPFLAGS := -O3

CLANG_CONFIG_EXTRA_LDFLAGS :=

CLANG_CONFIG_EXTRA_CFLAGS += \

@@ -40,7 +40,7 @@ CLANG_CONFIG_EXTRA_CFLAGS += \

# Help catch common 32/64-bit errors.

CLANG_CONFIG_EXTRA_CFLAGS += \

- -Werror=int-conversion

+ -Werror=int-conversion

# Workaround for ccache with clang.

# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.

@@ -49,6 +49,7 @@ CLANG_CONFIG_EXTRA_CFLAGS += \

CLANG_CONFIG_UNKNOWN_CFLAGS := \

-funswitch-loops \

+ -O3 \

-fno-tree-sra \

-finline-limit=64 \

-Wno-psabi \

@@ -61,14 +62,14 @@ CLANG_CONFIG_UNKNOWN_CFLAGS := \

# Clang flags for all host rules

CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=

-CLANG_CONFIG_HOST_EXTRA_CFLAGS :=

-CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=

+CLANG_CONFIG_HOST_EXTRA_CFLAGS := -O3

+CLANG_CONFIG_HOST_EXTRA_CPPFLAGS := -O3

CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=

# Clang flags for all target rules

CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=

-CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc

-CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc

+CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc -O3

+CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc -O3

CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=

# HOST config

@@ -98,7 +99,7 @@ CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES := $(LLVM_PREBUILTS_HEADER_PATH) $(TARGET_O

# Address sanitizer clang config

ADDRESS_SANITIZER_RUNTIME_LIBRARY := libclang_rt.asan_$(TARGET_ARCH)_android

-ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fsanitize=address -fno-omit-frame-pointer

+ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fsanitize=address -fno-omit-frame-pointer -O3

ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit

ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl $(ADDRESS_SANITIZER_RUNTIME_LIBRARY)

ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan

diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk

index 95b1804..de703fe 100644

--- a/core/combo/TARGET_linux-arm.mk

+++ b/core/combo/TARGET_linux-arm.mk

@@ -38,7 +38,7 @@ endif

$(combo_2nd_arch_prefix)TARGET_NDK_GCC_VERSION := 4.8

ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)

-$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := 4.8

+$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := linaro-4.9

else

$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)

endif

@@ -67,14 +67,14 @@ $(combo_2nd_arch_prefix)TARGET_STRIP := $($(combo_2nd_arch_prefix)TARGET_TOOLS_P

$(combo_2nd_arch_prefix)TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined

-$(combo_2nd_arch_prefix)TARGET_arm_CFLAGS := -O2 \

+$(combo_2nd_arch_prefix)TARGET_arm_CFLAGS := -O3 \

-fomit-frame-pointer \

-fstrict-aliasing \

-funswitch-loops

# Modules can choose to compile some source as thumb.

$(combo_2nd_arch_prefix)TARGET_thumb_CFLAGS := -mthumb \

- -Os \

+ -O3 \

-fomit-frame-pointer \

-fno-strict-aliasing

@@ -96,6 +96,7 @@ android_config_h := $(call select-android-config-h,linux-arm)

$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += \

-msoft-float \

+	-O3 \

-ffunction-sections \

-fdata-sections \

-funwind-tables \

@@ -127,7 +128,7 @@ endif

# in their exported C++ functions). Also, GCC 4.5 has already

# removed the warning from the compiler.

#

-$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -Wno-psabi

+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -Wno-psabi -O3

$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += \

-Wl,-z,noexecstack \

@@ -140,12 +141,12 @@ $(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += \

$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -mthumb-interwork

-$(combo_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden

+$(combo_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden -O3

# More flags/options can be added here

$(combo_2nd_arch_prefix)TARGET_RELEASE_CFLAGS := \

-DNDEBUG \

-	-g \

+	-O3 \

-Wstrict-aliasing=2 \

-fgcse-after-reload \

-frerun-cse-after-loop \

diff --git a/core/combo/TARGET_linux-arm64.mk b/core/combo/TARGET_linux-arm64.mk

index df6c127..2d1de81 100644

--- a/core/combo/TARGET_linux-arm64.mk

+++ b/core/combo/TARGET_linux-arm64.mk

@@ -38,7 +38,7 @@ endif

TARGET_NDK_GCC_VERSION := 4.9

ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)

-TARGET_GCC_VERSION := 4.9

+TARGET_GCC_VERSION := linaro-4.9

else

TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)

endif

@@ -68,7 +68,7 @@ TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)

TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined

TARGET_GLOBAL_CFLAGS += \

- -fno-strict-aliasing \

+ -O3 -fno-strict-aliasing \

android_config_h := $(call select-android-config-h,linux-arm64)

@@ -113,12 +113,12 @@ TARGET_GLOBAL_LDFLAGS += \

-Wl,-maarch64linux \

$(arch_variant_ldflags)

-TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden

+TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden -O3

# More flags/options can be added here

TARGET_RELEASE_CFLAGS := \

-DNDEBUG \

-	-O2 -g \

+	-O3 \

-Wstrict-aliasing=2 \

-fgcse-after-reload \

-frerun-cse-after-loop \

diff --git a/core/combo/arch/arm64/armv8-a.mk b/core/combo/arch/arm64/armv8-a.mk

index 642fe91..9b959b6 100644

--- a/core/combo/arch/arm64/armv8-a.mk

+++ b/core/combo/arch/arm64/armv8-a.mk

@@ -8,6 +8,6 @@ endif

# Leave the flag so devices that need the workaround but don't fit in

# the check above can still enable it.

ifeq ($(TARGET_CPU_CORTEX_A53),true)

-arch_variant_ldflags := -Wl,--fix-cortex-a53-843419 \

+#arch_variant_ldflags := -Wl,--fix-cortex-a53-843419 \

-Wl,--fix-cortex-a53-835769

endif

diff --git a/core/combo/select.mk b/core/combo/select.mk

index ec10dd2..ec5781f 100644

--- a/core/combo/select.mk

+++ b/core/combo/select.mk

@@ -49,9 +49,9 @@ $(combo_var_prefix)HAVE_STRLCPY := 0

$(combo_var_prefix)HAVE_STRLCAT := 0

$(combo_var_prefix)HAVE_KERNEL_MODULES := 0

-$(combo_var_prefix)GLOBAL_CFLAGS := -fno-exceptions -Wno-multichar

-$(combo_var_prefix)RELEASE_CFLAGS := -O2 -g -fno-strict-aliasing

-$(combo_var_prefix)GLOBAL_CPPFLAGS :=

+$(combo_var_prefix)GLOBAL_CFLAGS := -fno-exceptions -Wno-multichar -O3

+$(combo_var_prefix)RELEASE_CFLAGS := -O3 -fno-strict-aliasing

+$(combo_var_prefix)GLOBAL_CPPFLAGS := -O3

$(combo_var_prefix)GLOBAL_LDFLAGS :=

$(combo_var_prefix)GLOBAL_ARFLAGS := crsPD

$(combo_var_prefix)GLOBAL_LD_DIRS :=

diff --git a/core/config.mk b/core/config.mk

index ddc4007..0ef7cea 100644

--- a/core/config.mk

+++ b/core/config.mk

@@ -113,8 +113,8 @@ SHOW_COMMANDS:= $(filter showcommands,$(MAKECMDGOALS))

# ###############################################################

# These can be changed to modify both host and device modules.

-COMMON_GLOBAL_CFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith

-COMMON_RELEASE_CFLAGS:= -DNDEBUG -UDEBUG

+COMMON_GLOBAL_CFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -O3

+COMMON_RELEASE_CFLAGS:= -DNDEBUG -UDEBUG -O3

COMMON_GLOBAL_CPPFLAGS:= $(COMMON_GLOBAL_CFLAGS) -Wsign-promo

COMMON_RELEASE_CPPFLAGS:= $(COMMON_RELEASE_CFLAGS)

4. execute the command "brunch cm_ferrari-user"

Steps use this build.

1. Builds can be downloaded from here -

cm-12.1-20150803-UNOFFICIAL-ferrari.zip

http://d-h.st/tmmW

cm-12.1-20150806-UNOFFICIAL-ferrari.zip

http://d-h.st/raM0

cm-12.1-20150811-UNOFFICIAL-ferrari.zip

http://d-h.st/9PFq

cm-12.1-20150815-UNOFFICIAL-ferrari.zip

http://d-h.st/YAnS

cm-12.1-20150827-UNOFFICIAL-ferrari.zip

http://d-h.st/cIZg

cm-12.1-20150916-UNOFFICIAL-ferrari.zip

http://d-h.st/jqbq

cm-12.1-20150924-UNOFFICIAL-ferrari.zip

http://d-h.st/YcOn

cm-12.1-20151009-UNOFFICIAL-ferrari.zip

http://d-h.st/Vmp3

2. Download any 64bit gapps.

3. Install twrp and these two files.

I used the sensor patch from this thread http://xdaforums.com/mi-4i/development/wip-cyanogenmod-12-1-xiaomi-mi-4i-t3152134

I have attached the AnTuTu benchmark score