LLVM IR Lowering: support "select"

This commit adds support for the "select" operation that lowers directly into
its LLVM IR counterpart.  A simple test is included.

PiperOrigin-RevId: 227527893
This commit is contained in:
Alex Zinenko 2019-01-02 08:52:19 -08:00 committed by jpienaar
parent 50a356d118
commit 0565067495
2 changed files with 14 additions and 2 deletions

View File

@ -712,6 +712,14 @@ bool ModuleLowerer::convertInstruction(const OperationInst &inst) {
return false;
}
if (auto selectOp = inst.dyn_cast<SelectOp>()) {
valueMapping[selectOp->getResult()] =
builder.CreateSelect(valueMapping.lookup(selectOp->getCondition()),
valueMapping.lookup(selectOp->getTrueValue()),
valueMapping.lookup(selectOp->getFalseValue()));
return false;
}
// Terminators.
if (auto returnInst = inst.dyn_cast<ReturnOp>()) {
unsigned numOperands = returnInst->getNumOperands();

View File

@ -614,7 +614,11 @@ cfgfunc @ops(f32, f32, i32, i32) -> (f32, i32) {
^bb0(%arg0: f32, %arg1: f32, %arg2: i32, %arg3: i32):
// CHECK-NEXT: fsub float %0, %1
%0 = subf %arg0, %arg1: f32
// CHECK-NEXT: sub i32 %2, %3
// CHECK-NEXT: %6 = sub i32 %2, %3
%1 = subi %arg2, %arg3: i32
return %0, %1 : f32, i32
// CHECK-NEXT: %7 = icmp slt i32 %2, %6
%2 = cmpi "slt", %arg2, %1 : i32
// CHECK-NEXT: select i1 %7, i32 %2, i32 %6
%3 = select %2, %arg2, %1 : i32
return %0, %3 : f32, i32
}