aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2002-12-03 07:36:03 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2002-12-03 07:36:03 +0000
commit07f02614f668693e8f2ed562c52e5664ff1ce0fe (patch)
tree17e754e3c7028d5c73fdda7356fe744ece6b50b0
parentea1ddab58e9db323294012628a56275da0e930a7 (diff)
brg
Add support for cast ... to bool in visitCastInst (it's a start, anyways...) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4883 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp17
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp17
2 files changed, 28 insertions, 6 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index a601660413..ac4084cbbb 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -641,9 +641,20 @@ ISel::visitCastInst (CastInst &CI)
//the former is that the register allocator could use any register it wants,
//but for now this obviously doesn't matter. :)
-// if target type is bool
-// Emit Compare
-// Emit Set-if-not-zero
+ Type *targetType = CI.getType ();
+ Value *operand = CI.getOperand (0);
+ unsigned int operandReg = getReg (operand);
+ Type *sourceType = operand->getType ();
+ unsigned int destReg = getReg (CI);
+
+ // cast to bool:
+ if (targetType == Type::BoolTy) {
+ // Emit Compare
+ BuildMI (BB, X86::CMPri8, 2).addReg (operandReg).addZImm (0);
+ // Emit Set-if-not-zero
+ BuildMI (BB, X86::SETNEr, 1, destReg);
+ return;
+ }
// if size of target type == size of source type
// Emit Mov reg(target) <- reg(source)
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index a601660413..ac4084cbbb 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -641,9 +641,20 @@ ISel::visitCastInst (CastInst &CI)
//the former is that the register allocator could use any register it wants,
//but for now this obviously doesn't matter. :)
-// if target type is bool
-// Emit Compare
-// Emit Set-if-not-zero
+ Type *targetType = CI.getType ();
+ Value *operand = CI.getOperand (0);
+ unsigned int operandReg = getReg (operand);
+ Type *sourceType = operand->getType ();
+ unsigned int destReg = getReg (CI);
+
+ // cast to bool:
+ if (targetType == Type::BoolTy) {
+ // Emit Compare
+ BuildMI (BB, X86::CMPri8, 2).addReg (operandReg).addZImm (0);
+ // Emit Set-if-not-zero
+ BuildMI (BB, X86::SETNEr, 1, destReg);
+ return;
+ }
// if size of target type == size of source type
// Emit Mov reg(target) <- reg(source)