Fix fast-isel to not emit invalid assembly when presented with a
authorDan Gohman <gohman@apple.com>
Sat, 20 Dec 2008 17:19:40 +0000 (17:19 +0000)
committerDan Gohman <gohman@apple.com>
Sat, 20 Dec 2008 17:19:40 +0000 (17:19 +0000)
constant shift count that doesn't fit in the shift instruction's
immediate field. This fixes PR3242.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FastISel.cpp
test/CodeGen/X86/fast-isel-shift-imm.ll [new file with mode: 0644]

index c4b45bf431ea857ed4903619f515dcb585dbbf57..a81ecfeace18411b63677c7f080da514427fcd69 100644 (file)
@@ -893,7 +893,7 @@ bool X86FastISel::X86SelectShift(Instruction *I) {
   if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
     unsigned ResultReg = createResultReg(RC);
     BuildMI(MBB, TII.get(OpImm), 
-            ResultReg).addReg(Op0Reg).addImm(CI->getZExtValue());
+            ResultReg).addReg(Op0Reg).addImm(CI->getZExtValue() & 0xff);
     UpdateValueMap(I, ResultReg);
     return true;
   }
diff --git a/test/CodeGen/X86/fast-isel-shift-imm.ll b/test/CodeGen/X86/fast-isel-shift-imm.ll
new file mode 100644 (file)
index 0000000..c47b990
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | llc -march=x86 -fast | grep {sarl        \$80, %eax}
+; PR3242
+
+define i32 @foo(i32 %x) nounwind {
+  %y = ashr i32 %x, 50000
+  ret i32 %y
+}