aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Transforms/NaCl/PromoteIntegers.cpp10
-rw-r--r--test/Transforms/NaCl/promote-load-of-bc.ll26
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/Transforms/NaCl/PromoteIntegers.cpp b/lib/Transforms/NaCl/PromoteIntegers.cpp
index f12bc883c6..d48bdfc37b 100644
--- a/lib/Transforms/NaCl/PromoteIntegers.cpp
+++ b/lib/Transforms/NaCl/PromoteIntegers.cpp
@@ -100,8 +100,10 @@ static Type *getPromotedType(Type *Ty) {
// Return true if Val is an int or pointer-to-int which should be converted.
static bool shouldConvert(Value *Val) {
Type *Ty = Val->getType();
+#if 0 // XXX EMSCRIPTEN: We don't need to convert pointers.
if (PointerType *Pty = dyn_cast<PointerType>(Ty))
Ty = Pty->getContainedType(0);
+#endif
if (IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
if (!isLegalSize(ITy->getBitWidth())) {
return true;
@@ -247,10 +249,12 @@ static Value *splitLoad(LoadInst *Inst, ConversionState &State) {
Value *LoadHi = IRB.CreateAlignedLoad(BCHi, 1, Inst->getName() + ".hi"); // XXX EMSCRIPTEN: worst-case alignment assumption
if (!isLegalSize(Width - LoWidth)) {
LoadHi = splitLoad(cast<LoadInst>(LoadHi), State);
+#if 0 /// XXX EMSCRIPTEN: We don't need to convert pointers.
// BCHi was still illegal, and has been replaced with a placeholder in the
// recursive call. Since it is redundant with BCLo in the recursive call,
// just splice it out entirely.
State.recordConverted(cast<Instruction>(BCHi), GEPHi, /*TakeName=*/false);
+#endif
}
Value *HiExt = IRB.CreateZExt(LoadHi, NewType, LoadHi->getName() + ".ext");
@@ -319,12 +323,8 @@ static Value *splitStore(StoreInst *Inst, ConversionState &State) {
// BCHi was still illegal, and has been replaced with a placeholder in the
// recursive call. Since it is redundant with BCLo in the recursive call,
// just splice it out entirely.
-#if 0 /// XXX EMSCRIPTEN: Allow these to be ConstantExprs
+#if 0 /// XXX EMSCRIPTEN: We don't need to convert pointers.
State.recordConverted(cast<Instruction>(BCHi), GEPHi, /*TakeName=*/false);
-#else
- if (Instruction *BCHiInst = dyn_cast<Instruction>(BCHi)) {
- State.recordConverted(BCHiInst, GEPHi, /*TakeName=*/false);
- }
#endif
}
State.recordConverted(Inst, StoreHi, /*TakeName=*/false);
diff --git a/test/Transforms/NaCl/promote-load-of-bc.ll b/test/Transforms/NaCl/promote-load-of-bc.ll
new file mode 100644
index 0000000000..9c02e9e6e3
--- /dev/null
+++ b/test/Transforms/NaCl/promote-load-of-bc.ll
@@ -0,0 +1,26 @@
+; RUN: opt -S -nacl-promote-ints < %s | FileCheck %s
+
+target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32"
+
+@from = external global [300 x i8]
+@to = external global [300 x i8]
+
+; CHECK: define void @load_bc_to_i80() {
+; CHECK-NEXT: %loaded.short.lo = load i64* bitcast ([300 x i8]* @from to i64*), align 4
+; CHECK-NEXT: %loaded.short.lo.ext = zext i64 %loaded.short.lo to i128
+; CHECK-NEXT: %loaded.short.hi = load i16* bitcast (i64* getelementptr (i64* bitcast ([300 x i8]* @from to i64*), i32 1) to i16*)
+; CHECK-NEXT: %loaded.short.hi.ext = zext i16 %loaded.short.hi to i128
+; CHECK-NEXT: %loaded.short.hi.ext.sh = shl i128 %loaded.short.hi.ext, 64
+; CHECK-NEXT: %loaded.short = or i128 %loaded.short.lo.ext, %loaded.short.hi.ext.sh
+; CHECK-NEXT: %loaded.short.lo1 = trunc i128 %loaded.short to i64
+; CHECK-NEXT: store i64 %loaded.short.lo1, i64* bitcast ([300 x i8]* @to to i64*), align 4
+; CHECK-NEXT: %loaded.short.hi.sh = lshr i128 %loaded.short, 64
+; CHECK-NEXT: %loaded.short.hi2 = trunc i128 %loaded.short.hi.sh to i16
+; CHECK-NEXT: store i16 %loaded.short.hi2, i16* bitcast (i64* getelementptr (i64* bitcast ([300 x i8]* @to to i64*), i32 1) to i16*)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @load_bc_to_i80() {
+ %loaded.short = load i80* bitcast ([300 x i8]* @from to i80*), align 4
+ store i80 %loaded.short, i80* bitcast ([300 x i8]* @to to i80*), align 4
+ ret void
+}