[PATCH] Type conversion bug when anlyze compare

Xu Jiangwei David.Xu at arm.com
Mon Aug 4 00:35:55 PDT 2014


In analyzeCompare() function in AArch64InstrInfo.cpp, the return val type of decodeLogicalImmediate is uint64_t, while CmpValue is int, it causes a bug when converting uint64_t to int. The bug was found in spec2006-483.xalancbmk. CmpValue is only used to compare with zero in OptimizeCompareInstr(), so we can fix it by comparing it with zero in analyzeCompare().

http://reviews.llvm.org/D4771

Files:
  lib/Target/AArch64/AArch64InstrInfo.cpp

Index: lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- lib/Target/AArch64/AArch64InstrInfo.cpp
+++ lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -650,9 +650,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;
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4771.12150.patch
Type: text/x-patch
Size: 866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140804/1044cc7c/attachment.bin>


More information about the llvm-commits mailing list