[polly] r272502 - Recommit: "Simplify min/max expression generation"
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 11 21:49:42 PDT 2016
Author: grosser
Date: Sat Jun 11 23:49:41 2016
New Revision: 272502
URL: http://llvm.org/viewvc/llvm-project?rev=272502&view=rev
Log:
Recommit: "Simplify min/max expression generation"
As part of this simplification we pull complex logic out of the loop body and
skip the previously redundantly executed first loop iteration.
This is a partial recommit of r271514 and r271535 which where in conflict with
the revert in r272483 and consequently also had to be reverted temporarily. The
original patch was contributed by Johannes Doerfert.
This patch is mostly a NFC, but dropping the first loop iteration can sometimes
result in slightly simpler code.
Modified:
polly/trunk/lib/CodeGen/IslExprBuilder.cpp
Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=272502&r1=272501&r2=272502&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Sat Jun 11 23:49:41 2016
@@ -171,14 +171,22 @@ Value *IslExprBuilder::createOpNAry(__is
assert(isl_ast_expr_get_op_n_arg(Expr) >= 2 &&
"We need at least two operands in an n-ary operation");
- Value *V;
-
- V = create(isl_ast_expr_get_op_arg(Expr, 0));
+ CmpInst::Predicate Pred;
+ switch (isl_ast_expr_get_op_type(Expr)) {
+ default:
+ llvm_unreachable("This is not a an n-ary isl ast expression");
+ case isl_ast_op_max:
+ Pred = CmpInst::ICMP_SGT;
+ break;
+ case isl_ast_op_min:
+ Pred = CmpInst::ICMP_SLT;
+ break;
+ }
- for (int i = 0; i < isl_ast_expr_get_op_n_arg(Expr); ++i) {
- Value *OpV;
- OpV = create(isl_ast_expr_get_op_arg(Expr, i));
+ Value *V = create(isl_ast_expr_get_op_arg(Expr, 0));
+ for (int i = 1; i < isl_ast_expr_get_op_n_arg(Expr); ++i) {
+ Value *OpV = create(isl_ast_expr_get_op_arg(Expr, i));
Type *Ty = getWidestType(V->getType(), OpV->getType());
if (Ty != OpV->getType())
@@ -187,21 +195,8 @@ Value *IslExprBuilder::createOpNAry(__is
if (Ty != V->getType())
V = Builder.CreateSExt(V, Ty);
- switch (isl_ast_expr_get_op_type(Expr)) {
- default:
- llvm_unreachable("This is no n-ary isl ast expression");
-
- case isl_ast_op_max: {
- Value *Cmp = Builder.CreateICmpSGT(V, OpV);
- V = Builder.CreateSelect(Cmp, V, OpV);
- continue;
- }
- case isl_ast_op_min: {
- Value *Cmp = Builder.CreateICmpSLT(V, OpV);
- V = Builder.CreateSelect(Cmp, V, OpV);
- continue;
- }
- }
+ Value *Cmp = Builder.CreateICmp(Pred, V, OpV);
+ V = Builder.CreateSelect(Cmp, V, OpV);
}
// TODO: We can truncate the result, if it fits into a smaller type. This can
More information about the llvm-commits
mailing list