[polly] r239025 - Mark sdivs as 'exact' instead of lowering them ourselves

Tobias Grosser tobias at grosser.es
Thu Jun 4 00:45:09 PDT 2015


Author: grosser
Date: Thu Jun  4 02:45:09 2015
New Revision: 239025

URL: http://llvm.org/viewvc/llvm-project?rev=239025&view=rev
Log:
Mark sdivs as 'exact' instead of lowering them ourselves

LLVM's instcombine already translates power-of-two sdivs that are known to be
exact to fast ashr instructions. Hence, there is no need to add this logic
ourselves.

Pointed-out-by: Johannes Doerfert

Modified:
    polly/trunk/lib/CodeGen/IslExprBuilder.cpp
    polly/trunk/test/Isl/CodeGen/exprModDiv.ll

Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=239025&r1=239024&r2=239025&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Thu Jun  4 02:45:09 2015
@@ -295,14 +295,7 @@ Value *IslExprBuilder::createOpBin(__isl
     Res = Builder.CreateNSWMul(LHS, RHS);
     break;
   case isl_ast_op_div:
-    if (auto *Const = dyn_cast<ConstantInt>(RHS)) {
-      auto &Val = Const->getValue();
-      if (Val.isPowerOf2() && Val.isNonNegative()) {
-        Res = Builder.CreateAShr(LHS, Val.ceilLogBase2(), "pexp.div.shr");
-        break;
-      }
-    }
-    Res = Builder.CreateSDiv(LHS, RHS, "pexp.div");
+    Res = Builder.CreateSDiv(LHS, RHS, "pexp.div", true);
     break;
   case isl_ast_op_pdiv_q: // Dividend is non-negative
     Res = Builder.CreateUDiv(LHS, RHS, "pexp.p_div_q");

Modified: polly/trunk/test/Isl/CodeGen/exprModDiv.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/exprModDiv.ll?rev=239025&r1=239024&r2=239025&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/exprModDiv.ll (original)
+++ polly/trunk/test/Isl/CodeGen/exprModDiv.ll Thu Jun  4 02:45:09 2015
@@ -42,7 +42,7 @@
 ; CHECK:  %polly.access.A10 = getelementptr float, float* %A, i64 %24
 
 ; A[p / 127]
-; CHECK:  %pexp.div = sdiv i64 %p, 127
+; CHECK:  %pexp.div = sdiv exact i64 %p, 127
 ; CHECK:  %polly.access.B12 = getelementptr float, float* %B, i64 %pexp.div
 
 ; A[i % 128]
@@ -64,8 +64,8 @@
 ; POW2:  %polly.access.A10 = getelementptr float, float* %A, i64 %24
 
 ; A[p / 128]
-; POW2:  %pexp.div.shr = ashr i64 %p, 7
-; POW2:  %polly.access.B12 = getelementptr float, float* %B, i64 %pexp.div.shr
+; POW2:  %pexp.div = sdiv exact i64 %p, 128
+; POW2:  %polly.access.B12 = getelementptr float, float* %B, i64 %pexp.div
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 





More information about the llvm-commits mailing list