summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-03-13 20:42:20 +0000
committerDan Gohman <gohman@apple.com>2009-03-13 20:42:20 +0000
commitc0bb959591aab5fb5088b85fbb5a97865ab95b5b (patch)
treed9dfd4db962d96dc9b713957d026d8cb8fd048fb /llvm/lib
parentb03d5a6b3670523984fe8665b29e5e3413a8d602 (diff)
downloadbcm5719-llvm-c0bb959591aab5fb5088b85fbb5a97865ab95b5b.tar.gz
bcm5719-llvm-c0bb959591aab5fb5088b85fbb5a97865ab95b5b.zip
Fix FastISel's assumption that i1 values are always zero-extended
by inserting explicit zero extensions where necessary. Included is a testcase where SelectionDAG produces a virtual register holding an i1 value which FastISel previously mistakenly assumed to be zero-extended. llvm-svn: 66941
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/FastISel.cpp15
-rw-r--r--llvm/lib/Target/X86/X86FastISel.cpp6
2 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index 229376d293c..3523dda97ea 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -497,7 +497,14 @@ bool FastISel::SelectCast(User *I, ISD::NodeType Opcode) {
if (!InputReg)
// Unhandled operand. Halt "fast" selection and bail.
return false;
-
+
+ // If the operand is i1, arrange for the high bits in the register to be zero.
+ if (I->getOperand(0)->getType() == Type::Int1Ty) {
+ InputReg = FastEmitZExtFromI1(SrcVT.getSimpleVT(), InputReg);
+ if (!InputReg)
+ return false;
+ }
+
unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
DstVT.getSimpleVT(),
Opcode,
@@ -970,3 +977,9 @@ unsigned FastISel::FastEmitInst_extractsubreg(MVT::SimpleValueType RetVT,
}
return ResultReg;
}
+
+/// FastEmitZExtFromI1 - Emit MachineInstrs to compute the value of Op
+/// with all but the least significant bit set to zero.
+unsigned FastISel::FastEmitZExtFromI1(MVT::SimpleValueType VT, unsigned Op) {
+ return FastEmit_ri(VT, VT, ISD::AND, Op, 1);
+}
diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp
index d6cdc3fb64a..50f1935dcdb 100644
--- a/llvm/lib/Target/X86/X86FastISel.cpp
+++ b/llvm/lib/Target/X86/X86FastISel.cpp
@@ -671,12 +671,14 @@ bool X86FastISel::X86SelectCmp(Instruction *I) {
}
bool X86FastISel::X86SelectZExt(Instruction *I) {
- // Special-case hack: The only i1 values we know how to produce currently
- // set the upper bits of an i8 value to zero.
+ // Handle zero-extension from i1 to i8, which is common.
if (I->getType() == Type::Int8Ty &&
I->getOperand(0)->getType() == Type::Int1Ty) {
unsigned ResultReg = getRegForValue(I->getOperand(0));
if (ResultReg == 0) return false;
+ // Set the high bits to zero.
+ ResultReg = FastEmitZExtFromI1(MVT::i8, ResultReg);
+ if (ResultReg == 0) return false;
UpdateValueMap(I, ResultReg);
return true;
}
OpenPOWER on IntegriCloud