[PATCH] D57327: [ARM] Thumb2: ConstantMaterializationCost

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 28 07:19:37 PST 2019


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: efriedma, samparker, dmgreen.
Herald added subscribers: kristof.beyls, javed.absar.

Constants can also be materialised using the negated value and a MVN, and this
case seem to have been missed for Thumb2. To check the constant materialisation
costs, we now call getT2SOImmVal twice, once for the original constant and then
also for its negated value, and this function checks if the constant can both
be splatted or rotated.

      

This was revealed by a test that optimises for minsize: instead of a LDR
literal pool load and having a literal pool entry, just a MVN with an immediate is
smaller (and also faster). This gives a small code size improvement for all our
apps in our code corpus, only 2 test cases have a tiny, insignificant
regression.


https://reviews.llvm.org/D57327

Files:
  lib/Target/ARM/ARMISelDAGToDAG.cpp
  test/CodeGen/ARM/shifter_operand.ll


Index: test/CodeGen/ARM/shifter_operand.ll
===================================================================
--- test/CodeGen/ARM/shifter_operand.ll
+++ test/CodeGen/ARM/shifter_operand.ll
@@ -256,3 +256,28 @@
 
   ret { i32, i32 } %ret
 }
+
+declare dso_local i32 @eat_const(i32)
+
+define hidden i32 @no_litpool() local_unnamed_addr #0 {
+; CHECK-LABEL:  no_litpool:
+; CHECK:        mov{{.*}} r0, #65536
+; CHECK:        mov{{.*}} r0, #-134217728
+; CHECK:        mvn r0, #-134217728
+entry:
+  %call0 = tail call i32 @eat_const(i32 65536)
+  %call1 = tail call i32 @eat_const(i32 -134217728)
+  %call2 = tail call i32 @eat_const(i32 134217727)
+  ret i32 %call2
+}
+
+define hidden i32 @litpool() local_unnamed_addr #0 {
+; CHECK-LABEL:  litpool:
+; CHECK:        ldr r0, {{.*}}LCPI{{.*}}
+; CHECK-NEXT:   b {{.*}}eat_const
+entry:
+  %call1 = tail call i32 @eat_const(i32 8388601)
+  ret i32 %call1
+}
+
+attributes #0 = { minsize nounwind optsize }
Index: lib/Target/ARM/ARMISelDAGToDAG.cpp
===================================================================
--- lib/Target/ARM/ARMISelDAGToDAG.cpp
+++ lib/Target/ARM/ARMISelDAGToDAG.cpp
@@ -451,7 +451,8 @@
   if (Subtarget->isThumb()) {
     if (Val <= 255) return 1;                               // MOV
     if (Subtarget->hasV6T2Ops() &&
-        (Val <= 0xffff || ARM_AM::getT2SOImmValSplatVal(Val) != -1))
+        (Val <= 0xffff || ARM_AM::getT2SOImmVal(Val) != -1 ||  // MOV
+         ARM_AM::getT2SOImmVal(~Val) != -1))                   // MVN
       return 1; // MOVW
     if (Val <= 510) return 2;                               // MOV + ADDi8
     if (~Val <= 255) return 2;                              // MOV + MVN


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57327.183854.patch
Type: text/x-patch
Size: 1687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/ae6431c6/attachment.bin>


More information about the llvm-commits mailing list