add support for bools to SELECT, this fixes Prolangs-C/bison from the
authorDuraid Madina <duraid@octopus.com.au>
Mon, 2 May 2005 06:41:13 +0000 (06:41 +0000)
committerDuraid Madina <duraid@octopus.com.au>
Mon, 2 May 2005 06:41:13 +0000 (06:41 +0000)
testsuite, however 09-vor is still dead (hopefully for other reasons!)

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

lib/Target/IA64/IA64ISelPattern.cpp

index 1fe9026ed0fa4ffa3b12a0c58538429e97ce066e..5ac5df5c93a889eb86506b5c2e6749d27a883003 100644 (file)
@@ -1054,19 +1054,48 @@ unsigned ISel::SelectExpr(SDOperand N) {
 
       switch (N.getOperand(1).getValueType()) {
         default: assert(0 &&
-        "ISD::SELECT: 'select'ing something other than i64 or f64!\n");
+        "ISD::SELECT: 'select'ing something other than i1, i64 or f64!\n");
+        // for i1, we load the condition into an integer register, then
+        // conditionally copy Tmp2 and Tmp3 to Tmp1 in parallel (only one
+        // of them will go through, since the integer register will hold
+        // either 0 or 1)
+        case MVT::i1: {
+          bogoResult=MakeReg(MVT::i1);
+
+          // load the condition into an integer register
+          unsigned condReg=MakeReg(MVT::i64);
+          unsigned dummy=MakeReg(MVT::i64);
+          BuildMI(BB, IA64::MOV, 1, dummy).addReg(IA64::r0);
+          BuildMI(BB, IA64::TPCADDIMM22, 2, condReg).addReg(dummy)
+            .addImm(1).addReg(Tmp1);
+
+          // initialize Result (bool) to false (hence UNC) and if
+          // the select condition (condReg) is false (0), copy Tmp3
+          BuildMI(BB, IA64::PCMPEQUNC, 3, bogoResult)
+            .addReg(condReg).addReg(IA64::r0).addReg(Tmp3);
+
+          // now, if the selection condition is true, write 1 to the
+          // result if Tmp2 is 1
+          BuildMI(BB, IA64::TPCMPNE, 3, Result).addReg(bogoResult)
+            .addReg(condReg).addReg(IA64::r0).addReg(Tmp2);
+          break;
+        }
+        // for i64/f64, we just copy Tmp3 and then conditionally overwrite it
+        // with Tmp2 if Tmp1 is true
         case MVT::i64:
           bogoResult=MakeReg(MVT::i64);
+          BuildMI(BB, IA64::MOV, 1, bogoResult).addReg(Tmp3);
+          BuildMI(BB, IA64::CMOV, 2, Result).addReg(bogoResult).addReg(Tmp2)
+            .addReg(Tmp1);
           break;
         case MVT::f64:
           bogoResult=MakeReg(MVT::f64);
+          BuildMI(BB, IA64::FMOV, 1, bogoResult).addReg(Tmp3);
+          BuildMI(BB, IA64::CFMOV, 2, Result).addReg(bogoResult).addReg(Tmp2)
+            .addReg(Tmp1);
           break;
       }
-
-      BuildMI(BB, IA64::MOV, 1, bogoResult).addReg(Tmp3);
-      BuildMI(BB, IA64::CMOV, 2, Result).addReg(bogoResult).addReg(Tmp2)
-        .addReg(Tmp1); // FIXME: should be FMOV/FCMOV sometimes,
-                       // though this will work for now (no JIT)
+      
       return Result;
   }