[LLVMdev] AArch64AddressTypePromotion does nothing (was Re: Contributing the Apple ARM64 compiler backend)

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Jun 30 16:19:57 PDT 2014


> On 2014-Jun-27, at 16:30, Jim Grosbach <grosbach at apple.com> wrote:
> 
> AArch64AddressTypePromotion.cpp does a fair bit of work to help make these things work out well. It could probably be generalized for non-AArch64 targets as per the comment in the file header.

I spent some time today generalizing AArch64AddressTypePromotion (I'll
send the patches when they're ready), but in the process discovered
that this pass does nothing (!) right now.  I assume this bug was
introduced when we changed the semantics of `Use` (IIRC, ARM64 was
still private at the time).

After the tiny patch inline below, the code looks even better:

--- old.s	2014-06-30 16:12:52.000000000 -0700
+++ new.s	2014-06-30 16:13:24.000000000 -0700
@@ -5,12 +5,10 @@
 _foo:                                   ; @foo
 	.cfi_startproc
 ; BB#0:                                 ; %entry
-	add	w8, w1, #1              ; =1
-	add	w9, w1, #2              ; =2
-	ldr	w8, [x0, w8, sxtw #2]
-	ldr	w9, [x0, w9, sxtw #2]
-	add	 w8, w9, w8
-	str	w8, [x0, w1, sxtw #2]
+	add	x8, x0, w1, sxtw #2
+	ldp	w9, w10, [x8, #4]
+	add	 w9, w10, w9
+	str	 w9, [x8]
 	ret
 	.cfi_endproc

I'll commit the fix once I've written up a testcase.

diff --git a/lib/Target/AArch64/AArch64AddressTypePromotion.cpp b/lib/Target/AArch64/AArch64AddressTypePromotion.cpp
index 04906f6..bcce295 100644
--- a/lib/Target/AArch64/AArch64AddressTypePromotion.cpp
+++ b/lib/Target/AArch64/AArch64AddressTypePromotion.cpp
@@ -212,12 +212,12 @@ static bool shouldSExtOperand(const Instruction *Inst, int OpIdx) {
 bool
 AArch64AddressTypePromotion::shouldConsiderSExt(const Instruction *SExt) const {
   if (SExt->getType() != ConsideredSExtType)
     return false;
 
-  for (const Use &U : SExt->uses()) {
-    if (isa<GetElementPtrInst>(*U))
+  for (const User *U : SExt->users()) {
+    if (isa<GetElementPtrInst>(U))
       return true;
   }
 
   return false;
 }




More information about the llvm-dev mailing list