[PATCH] [AArch64] Type conversion bug when anlyze compare

Xu Jiangwei David.Xu at arm.com
Wed Aug 6 20:25:28 PDT 2014


Test case is added in the new patch. Without the patch, an ANDS instruction will be deleted when doing peephole optimization.

http://reviews.llvm.org/D4771

Files:
  lib/Target/AArch64/AArch64InstrInfo.cpp
  test/CodeGen/AArch64/analyzecmp.ll

Index: lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- lib/Target/AArch64/AArch64InstrInfo.cpp
+++ lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -649,9 +649,12 @@
     SrcReg = MI->getOperand(1).getReg();
     SrcReg2 = 0;
     CmpMask = ~0;
-    CmpValue = AArch64_AM::decodeLogicalImmediate(
-        MI->getOperand(2).getImm(),
-        MI->getOpcode() == AArch64::ANDSWri ? 32 : 64);
+    // The return val type of decodeLogicalImmediate is uint64_t,
+    // while CmpValue is int, it causes a bug in spec2006-483.xalancbmk
+    // CmpValue is only used to compare with zero in OptimizeCompareInstr
+    CmpValue = (AArch64_AM::decodeLogicalImmediate(
+                    MI->getOperand(2).getImm(),
+                    MI->getOpcode() == AArch64::ANDSWri ? 32 : 64) != 0);
     return true;
   }
 
Index: test/CodeGen/AArch64/analyzecmp.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/analyzecmp.ll
@@ -0,0 +1,35 @@
+; RUN: llc -O3 -mcpu=cortex-a57 < %s | FileCheck %s 
+
+; CHECK-LABLE: @test
+; CHECK: tst [[CMP:x[0-9]+]], #0x8000000000000000
+; CHECK: csel [[R0:x[0-9]+]], [[S0:x[0-9]+]], [[S1:x[0-9]+]], eq
+; CHECK: csel [[R1:x[0-9]+]], [[S2:x[0-9]+]], [[S3:x[0-9]+]], eq
+target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
+target triple = "arm64--linux-gnueabi"
+
+define i64 @test(i64 %a) #0 align 2 {
+entry:
+  %conv = and i64 %a, 4294967295
+  %add = add nsw i64 %conv, -1
+  %div = sdiv i64 %add, 64
+  %rem = srem i64 %add, 64
+  %cmp = icmp slt i64 %rem, 0
+  br i1 %cmp, label %if.then, label %exit
+
+if.then:                                
+  %add2 = add nsw i64 %rem, 64
+  %add.ptr.sum = add i64 %div, -1
+  br label %exit
+
+exit:                 
+  %add.ptr.sum.pn = phi i64 [ %add.ptr.sum, %if.then ], [ %div, %entry ]
+  %__n.0 = phi i64 [ %add2, %if.then ], [ %rem, %entry ]
+  %storemerge = getelementptr inbounds i64* null, i64 %add.ptr.sum.pn
+  %conv4.mask = and i64 %__n.0, 4294967295
+  %shl.i.i = shl i64 1, %conv4.mask
+  %0 = load i64* %storemerge, align 8
+  %and.i = and i64 %shl.i.i, %0
+  ret  i64 %and.i  
+}
+
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4771.12266.patch
Type: text/x-patch
Size: 2188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140807/47e657de/attachment.bin>


More information about the llvm-commits mailing list