Use lowerCast instead of inlined _movzx, to get legalization, for memset.
Otherwise, there can be a movzx reg, 0, which is illegal,
when the memset value is constant 0.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3882
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/402253002
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index b572578..bfb7274 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -2101,7 +2101,8 @@
case IceType_v8i1: {
assert(Src0->getType() == IceType_i8);
InstCall *Call = makeHelperCall("Sz_bitcast_i8_to_v8i1", Dest, 1);
- Variable *Src0AsI32 = Func->makeVariable(IceType_i32, Context.getNode());
+ Variable *Src0AsI32 = Func->makeVariable(stackSlotType(),
+ Context.getNode());
// Arguments to functions are required to be at least 32 bits wide.
lowerCast(InstCast::create(Func, InstCast::Zext, Src0AsI32, Src0));
Call->addArg(Src0AsI32);
@@ -2110,7 +2111,8 @@
case IceType_v16i1: {
assert(Src0->getType() == IceType_i16);
InstCall *Call = makeHelperCall("Sz_bitcast_i16_to_v16i1", Dest, 1);
- Variable *Src0AsI32 = Func->makeVariable(IceType_i32, Context.getNode());
+ Variable *Src0AsI32 = Func->makeVariable(stackSlotType(),
+ Context.getNode());
// Arguments to functions are required to be at least 32 bits wide.
lowerCast(InstCast::create(Func, InstCast::Zext, Src0AsI32, Src0));
Call->addArg(Src0AsI32);
@@ -2708,8 +2710,8 @@
// because "push" only works for a specific operand size.
Operand *ValOp = Instr->getArg(1);
assert(ValOp->getType() == IceType_i8);
- Variable *ValExt = makeReg(stackSlotType());
- _movzx(ValExt, ValOp);
+ Variable *ValExt = Func->makeVariable(stackSlotType(), Context.getNode());
+ lowerCast(InstCast::create(Func, InstCast::Zext, ValExt, ValOp));
InstCall *Call = makeHelperCall("memset", NULL, 3);
Call->addArg(Instr->getArg(0));
Call->addArg(ValExt);
diff --git a/tests_lit/llvm2ice_tests/nacl-other-intrinsics.ll b/tests_lit/llvm2ice_tests/nacl-other-intrinsics.ll
index 8a11a84..bf0355f 100644
--- a/tests_lit/llvm2ice_tests/nacl-other-intrinsics.ll
+++ b/tests_lit/llvm2ice_tests/nacl-other-intrinsics.ll
@@ -132,6 +132,7 @@
ret void
}
; CHECK-LABEL: test_memset
+; CHECK: movzx
; CHECK: call memset
define void @test_memset_const_len_align(i32 %iptr_dst, i32 %wide_val) {
@@ -143,6 +144,18 @@
ret void
}
; CHECK-LABEL: test_memset_const_len_align
+; CHECK: movzx
+; CHECK: call memset
+
+define void @test_memset_const_val(i32 %iptr_dst, i32 %len) {
+entry:
+ %dst = inttoptr i32 %iptr_dst to i8*
+ call void @llvm.memset.p0i8.i32(i8* %dst, i8 0, i32 %len, i32 1, i1 0)
+ ret void
+}
+; CHECK-LABEL: test_memset_const_val
+; Make sure the argument is legalized (can't movzx reg, 0).
+; CHECK: movzx {{.*}}, {{[^0]}}
; CHECK: call memset
define i32 @test_setjmplongjmp(i32 %iptr_env) {