]> granicus.if.org Git - llvm/commitdiff
Do not expand SDIV when compiling for minimum code size
authorSjoerd Meijer <sjoerd.meijer@arm.com>
Fri, 8 Jul 2016 15:32:01 +0000 (15:32 +0000)
committerSjoerd Meijer <sjoerd.meijer@arm.com>
Fri, 8 Jul 2016 15:32:01 +0000 (15:32 +0000)
Differential Revision: http://reviews.llvm.org/D22139

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274855 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/ARM/urem-opt-size.ll

index 2931ad276a484a44270639ae006d072d417d2a96..3a67fe4ec9d403f386db60e41c1610ce524c3661 100644 (file)
@@ -14475,6 +14475,11 @@ SDValue DAGCombiner::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
 /// by a magic number.
 /// Ref: "Hacker's Delight" or "The PowerPC Compiler Writer's Guide".
 SDValue DAGCombiner::BuildSDIV(SDNode *N) {
+  // when optimising for minimum size, we don't want to expand a div to a mul
+  // and a shift.
+  if (DAG.getMachineFunction().getFunction()->optForMinSize())
+    return SDValue();
+
   ConstantSDNode *C = isConstOrConstSplat(N->getOperand(1));
   if (!C)
     return SDValue();
index 4c9aec10d0ffbaf7e4aa109f3a8c240b914984e0..7f1cd43bc4e3d0489065be5a0661d330f3bb83e0 100644 (file)
@@ -1,5 +1,5 @@
-; When optimising for minimum size, we don't want to expand a udiv to a mul
-; and a shift sequence. As a result, the urem instruction will not be
+; When optimising for minimum size, we don't want to expand a div to a mul
+; and a shift sequence. As a result, the urem instruction e.g. will not be
 ; expanded to a sequence of umull, lsrs, muls and sub instructions, but
 ; just a call to __aeabi_uidivmod.
 ;
@@ -8,9 +8,29 @@
 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
 target triple = "thumbv7m-arm-none-eabi"
 
-define i32 @foo() local_unnamed_addr #0 {
+define i32 @foo1() local_unnamed_addr #0 {
 entry:
-; CHECK-LABEL: foo:
+; CHECK-LABEL: foo1:
+; CHECK:__aeabi_idiv
+; CHECK-NOT: smmul
+  %call = tail call i32 bitcast (i32 (...)* @GetValue to i32 ()*)()
+  %div = sdiv i32 %call, 1000000
+  ret i32 %div
+}
+
+define i32 @foo2() local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: foo2:
+; CHECK: __aeabi_uidiv
+; CHECK-NOT: umull
+  %call = tail call i32 bitcast (i32 (...)* @GetValue to i32 ()*)()
+  %div = udiv i32 %call, 1000000
+  ret i32 %div
+}
+
+define i32 @foo3() local_unnamed_addr #0 {
+entry:
+; CHECK-LABEL: foo3:
 ; CHECK: __aeabi_uidivmod
 ; CHECK-NOT: umull
   %call = tail call i32 bitcast (i32 (...)* @GetValue to i32 ()*)()