Add FastISel support for floating-point operations.
authorDan Gohman <gohman@apple.com>
Wed, 20 Aug 2008 00:23:20 +0000 (00:23 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 20 Aug 2008 00:23:20 +0000 (00:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55021 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/FastISel.cpp
test/CodeGen/X86/fast-isel.ll

index f3fcaec28c331be8aac946dbee7c1596a35bc389..996cea0155c58b7c08aafa4ef75fb56414b2a1a6 100644 (file)
@@ -36,6 +36,7 @@ bool FastISel::SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
     // the given ISD opcode and type. Halt "fast" selection and bail.
     return false;
 
+  // We successfully emitted code for the given LLVM Instruction.
   ValueMap[I] = ResultReg;
   return true;
 }
@@ -53,12 +54,18 @@ FastISel::SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator En
 
   for (; I != End; ++I) {
     switch (I->getOpcode()) {
-    case Instruction::Add:
-      if (!SelectBinaryOp(I, ISD::ADD, ValueMap))  return I; break;
-    case Instruction::Sub:
-      if (!SelectBinaryOp(I, ISD::SUB, ValueMap))  return I; break;
-    case Instruction::Mul:
-      if (!SelectBinaryOp(I, ISD::MUL, ValueMap))  return I; break;
+    case Instruction::Add: {
+      ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD;
+      if (!SelectBinaryOp(I, Opc, ValueMap))  return I; break;
+    }
+    case Instruction::Sub: {
+      ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB;
+      if (!SelectBinaryOp(I, Opc, ValueMap))  return I; break;
+    }
+    case Instruction::Mul: {
+      ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL;
+      if (!SelectBinaryOp(I, Opc, ValueMap))  return I; break;
+    }
     case Instruction::SDiv:
       if (!SelectBinaryOp(I, ISD::SDIV, ValueMap)) return I; break;
     case Instruction::UDiv:
index 1b0d5b2f8f60f9a34b6532d7d48e0fd3a0bd13dd..b0be56b64b25171643fe6bdd6b8811a1ee5ba094 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | llc -fast-isel | grep add | count 1
+; RUN: llvm-as < %s | llc -fast-isel
 
 ; This tests very minimal fast-isel functionality.
 
@@ -21,3 +21,19 @@ exit:
   ret i32 %t5
 }
 
+define double @bar(double* %p, double* %q) {
+entry:
+  %r = load double* %p
+  %s = load double* %q
+  br label %fast
+
+fast:
+  %t0 = add double %r, %s
+  %t1 = mul double %t0, %s
+  %t2 = sub double %t1, %s
+  br label %exit
+
+exit:
+  ret double %t2
+}
+