Implement rotate using funnel shift on LLVM >= 7

Implement the rotate_left and rotate_right operations using
llvm.fshl and llvm.fshr if they are available (LLVM >= 7).

Originally I wanted to expose the funnel_shift_left and
funnel_shift_right intrinsics and implement rotate_left and
rotate_right on top of them. However, emulation of funnel
shifts requires emitting a conditional to check for zero shift
amount, which is not necessary for rotates. I was uncomfortable
doing that here, as I don't want to rely on LLVM to optimize
away that conditional (and for variable rotates, I'm not sure it
can). We should revisit that question when we raise our minimum
version requirement to LLVM 7 and don't need emulation code
anymore.
This commit is contained in:
Nikita Popov 2018-11-03 15:48:29 +01:00
parent 2ad8c7b350
commit 4c40ff6a24
10 changed files with 93 additions and 8 deletions

View file

@ -23,6 +23,7 @@ use value::Value;
use llvm;
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
DICompositeType, DILexicalBlock, DIFlags};
use llvm_util;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc::hir::CodegenFnAttrFlags;
@ -1169,9 +1170,8 @@ fn prepare_union_metadata(
fn use_enum_fallback(cx: &CodegenCx) -> bool {
// On MSVC we have to use the fallback mode, because LLVM doesn't
// lower variant parts to PDB.
return cx.sess().target.target.options.is_like_msvc || unsafe {
llvm::LLVMRustVersionMajor() < 7
};
return cx.sess().target.target.options.is_like_msvc
|| llvm_util::get_major_version() < 7;
}
// Describes the members of an enum value: An enum is described as a union of