[polly] r271514 - [NFC] Simplify min/max expression generation

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 04:21:08 PDT 2016


Author: jdoerfert
Date: Thu Jun  2 06:20:52 2016
New Revision: 271514

URL: http://llvm.org/viewvc/llvm-project?rev=271514&view=rev
Log:
[NFC] Simplify min/max expression generation

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=271514&r1=271513&r2=271514&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Thu Jun  2 06:20:52 2016
@@ -178,32 +178,18 @@ Value *IslExprBuilder::createOpNAry(__is
          "isl ast expression not of type isl_ast_op");
   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));
+  assert((isl_ast_expr_get_op_type(Expr) == isl_ast_op_max ||
+          isl_ast_expr_get_op_type(Expr) == isl_ast_op_min) &&
+         "This is no n-ary isl ast expression");
+
+  bool IsMax = isl_ast_expr_get_op_type(Expr) == isl_ast_op_max;
+  auto Pred = IsMax ? CmpInst::ICMP_SGT : CmpInst::ICMP_SLT;
+  auto *V = create(isl_ast_expr_get_op_arg(Expr, 0));
 
   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));
-
+    auto *OpV = create(isl_ast_expr_get_op_arg(Expr, i));
     unifyTypes(V, OpV);
-
-    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;
-    }
-    }
+    V = Builder.CreateSelect(Builder.CreateICmp(Pred, V, OpV), 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