Skip to content

Commit 63f0c4d

Browse files
committed
Support removed LLVM intrinsics by invoking its AutoUpgrade mechanism.
1 parent a0b4e67 commit 63f0c4d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/rustllvm/PassWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Support/Host.h"
1818
#include "llvm/Analysis/TargetLibraryInfo.h"
1919
#include "llvm/Analysis/TargetTransformInfo.h"
20+
#include "llvm/IR/AutoUpgrade.h"
2021
#include "llvm/Target/TargetMachine.h"
2122
#include "llvm/Target/TargetSubtargetInfo.h"
2223
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
@@ -361,10 +362,17 @@ extern "C" void
361362
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
362363
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
363364
P->doInitialization();
365+
366+
// Upgrade all calls to old intrinsics first.
367+
for (Module::iterator I = unwrap(M)->begin(),
368+
E = unwrap(M)->end(); I != E;)
369+
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
370+
364371
for (Module::iterator I = unwrap(M)->begin(),
365372
E = unwrap(M)->end(); I != E; ++I)
366373
if (!I->isDeclaration())
367374
P->run(*I);
375+
368376
P->doFinalization();
369377
}
370378

src/test/run-pass/simd-upgraded.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that removed LLVM SIMD intrinsics continue
12+
// to work via the "AutoUpgrade" mechanism.
13+
14+
#![feature(cfg_target_feature, repr_simd)]
15+
#![feature(platform_intrinsics, stmt_expr_attributes)]
16+
17+
#[repr(simd)]
18+
#[derive(PartialEq, Debug)]
19+
struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
20+
21+
fn main() {
22+
#[cfg(target_feature = "sse2")] unsafe {
23+
extern "platform-intrinsic" {
24+
fn x86_mm_min_epi16(x: i16x8, y: i16x8) -> i16x8;
25+
}
26+
assert_eq!(x86_mm_min_epi16(i16x8(0, 1, 2, 3, 4, 5, 6, 7),
27+
i16x8(7, 6, 5, 4, 3, 2, 1, 0)),
28+
i16x8(0, 1, 2, 3, 3, 2, 1, 0));
29+
};
30+
}

0 commit comments

Comments
 (0)