[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Fri May 7 11:23:05 PDT 2004
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.33 -> 1.34
---
Log message:
Expand min/max/abs in terms of select instead of explicit branching
---
Diffs of the changes: (+12 -16)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.33 llvm-gcc/gcc/llvm-expand.c:1.34
--- llvm-gcc/gcc/llvm-expand.c:1.33 Wed Apr 21 13:57:57 2004
+++ llvm-gcc/gcc/llvm-expand.c Fri May 7 11:23:19 2004
@@ -4082,34 +4082,30 @@
llvm_basicblock *FromBlock =llvm_ilist_back(llvm_basicblock, Fn->BasicBlocks);
enum InstOpcode Opcode;
llvm_value *Compare;
- llvm_instruction *PHI;
+ llvm_instruction *Select;
+ const char *Name;
assert(op0->Ty == op1->Ty && "Operands must have same type!");
assert(llvm_type_is_scalar(op0->Ty) && "Min/Max/Abs require scalar type!");
switch (TREE_CODE(exp)) {
- case ABS_EXPR: Opcode = O_SetGE; break;
- case MAX_EXPR: Opcode = O_SetGE; break;
- case MIN_EXPR: Opcode = O_SetLE; break;
+ case ABS_EXPR: Opcode = O_SetGE; Name = "abs"; break;
+ case MAX_EXPR: Opcode = O_SetGE; Name = "max"; break;
+ case MIN_EXPR: Opcode = O_SetLE; Name = "min"; break;
default: abort();
}
/* FIXME: This could use a conditional move instead of branches! */
Compare = append_inst(Fn, create_binary_inst("comp", Opcode, op0, op1));
- append_inst(Fn, create_cond_branch(Compare, Cont, Stub));
- llvm_emit_label(Fn, Stub);
if (TREE_CODE(exp) == ABS_EXPR)
- op1 = append_inst(Fn, create_binary_inst("abs", O_Sub, op1, op0));
-
- append_inst(Fn, create_uncond_branch(Cont));
- llvm_emit_label(Fn, Cont);
- PHI = llvm_instruction_new(op0->Ty, "minmax", O_PHINode, 4);
- PHI->Operands[0] = op0;
- PHI->Operands[1] = D2V(FromBlock);
- PHI->Operands[2] = op1;
- PHI->Operands[3] = D2V(Stub);
- return append_inst(Fn, PHI);
+ op1 = append_inst(Fn, create_binary_inst("abs.pos", O_Sub, op1, op0));
+
+ Select = llvm_instruction_new(op0->Ty, Name, O_Select, 3);
+ Select->Operands[0] = Compare;
+ Select->Operands[1] = op0;
+ Select->Operands[2] = op1;
+ return append_inst(Fn, Select);
}
static llvm_function *CreateIntrinsicFnWithType(const char *Name,
More information about the llvm-commits
mailing list