Commit c5c8957b by Jim Stichnoth

Subzero: Fix x86 lowering for shift-by-relocatable-constant.

Trying to shift by a ConstantRelocatable causes an assertion failure in the integrated assembler, because the shift value must be Imm8. Maybe this is possible to express via ELF relocations, but it doesn't seem worth it. Especially since ConstantRelocatables refer to addresses and it doesn't make sense to shift by an address. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4256 R=jvoung@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/1262003003.
parent 713dbdec
...@@ -1835,21 +1835,21 @@ void TargetX86Base<Machine>::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1835,21 +1835,21 @@ void TargetX86Base<Machine>::lowerArithmetic(const InstArithmetic *Inst) {
break; break;
case InstArithmetic::Shl: case InstArithmetic::Shl:
_mov(T, Src0); _mov(T, Src0);
if (!llvm::isa<Constant>(Src1)) if (!llvm::isa<ConstantInteger32>(Src1))
Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx); Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx);
_shl(T, Src1); _shl(T, Src1);
_mov(Dest, T); _mov(Dest, T);
break; break;
case InstArithmetic::Lshr: case InstArithmetic::Lshr:
_mov(T, Src0); _mov(T, Src0);
if (!llvm::isa<Constant>(Src1)) if (!llvm::isa<ConstantInteger32>(Src1))
Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx); Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx);
_shr(T, Src1); _shr(T, Src1);
_mov(Dest, T); _mov(Dest, T);
break; break;
case InstArithmetic::Ashr: case InstArithmetic::Ashr:
_mov(T, Src0); _mov(T, Src0);
if (!llvm::isa<Constant>(Src1)) if (!llvm::isa<ConstantInteger32>(Src1))
Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx); Src1 = legalizeToReg(Src1, Traits::RegisterSet::Reg_ecx);
_sar(T, Src1); _sar(T, Src1);
_mov(Dest, T); _mov(Dest, T);
......
...@@ -207,3 +207,35 @@ entry: ...@@ -207,3 +207,35 @@ entry:
; ARM32HWDIV: bne ; ARM32HWDIV: bne
; ARM32HWDIV: udiv ; ARM32HWDIV: udiv
; ARM32HWDIV: mls ; ARM32HWDIV: mls
; The following tests check that shift instructions don't try to use a
; ConstantRelocatable as an immediate operand.
@G = internal global [4 x i8] zeroinitializer, align 4
define i32 @ShlReloc(i32 %a) {
entry:
%opnd = ptrtoint [4 x i8]* @G to i32
%result = shl i32 %a, %opnd
ret i32 %result
}
; CHECK-LABEL: ShlReloc
; CHECK: shl {{.*}},cl
define i32 @LshrReloc(i32 %a) {
entry:
%opnd = ptrtoint [4 x i8]* @G to i32
%result = lshr i32 %a, %opnd
ret i32 %result
}
; CHECK-LABEL: LshrReloc
; CHECK: shr {{.*}},cl
define i32 @AshrReloc(i32 %a) {
entry:
%opnd = ptrtoint [4 x i8]* @G to i32
%result = ashr i32 %a, %opnd
ret i32 %result
}
; CHECK-LABEL: AshrReloc
; CHECK: sar {{.*}},cl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment