[PATCH] D52102: [ARM] Disallow icmp with negative imm and overflow

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 06:51:48 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL342392: [ARM] Disallow icmp with negative imm and overflow (authored by sam_parker, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52102?vs=165524&id=165755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52102

Files:
  llvm/trunk/lib/Target/ARM/ARMCodeGenPrepare.cpp
  llvm/trunk/test/CodeGen/ARM/arm-cgp-icmps.ll


Index: llvm/trunk/test/CodeGen/ARM/arm-cgp-icmps.ll
===================================================================
--- llvm/trunk/test/CodeGen/ARM/arm-cgp-icmps.ll
+++ llvm/trunk/test/CodeGen/ARM/arm-cgp-icmps.ll
@@ -288,3 +288,25 @@
   ret i32 %res
 }
 
+; CHECK-COMMON-LABEL: icmp_minus_imm
+; CHECK-NODSP: subs [[SUB:r[0-9]+]],
+; CHECK-NODSP: uxtb [[UXT:r[0-9]+]],
+; CHECK-NODSP: cmp [[UXT]], #251
+
+; CHECK-DSP: subs [[SUB:r[0-9]+]],
+; CHECK-DSP: uxtb [[UXT:r[0-9]+]],
+; CHECK-DSP: cmp [[UXT]], #251
+
+; CHECK-DSP-IMM: ldrb [[A:r[0-9]+]],
+; CHECK-DSP-IMM: movs  [[MINUS_7:r[0-9]+]], #249
+; CHECK-DSP-IMM: uadd8 [[RES:r[0-9]+]], [[A]], [[MINUS_7]]
+; CHECK-DSP-IMM: cmp [[RES]], #251
+define i32 @icmp_minus_imm(i8* %a) {
+entry:
+  %0 = load i8, i8* %a, align 1
+  %add.i = add i8 %0, -7
+  %cmp = icmp ugt i8 %add.i, -5
+  %conv1 = zext i1 %cmp to i32
+  ret i32 %conv1
+}
+
Index: llvm/trunk/lib/Target/ARM/ARMCodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/Target/ARM/ARMCodeGenPrepare.cpp
+++ llvm/trunk/lib/Target/ARM/ARMCodeGenPrepare.cpp
@@ -257,9 +257,20 @@
       return false;
 
     auto *CI = cast<ICmpInst>(*I->user_begin());
+    
+    // Don't support an icmp that deals with sign bits, including negative
+    // immediates
     if (CI->isSigned())
       return false;
 
+    if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(0)))
+      if (Const->isNegative())
+        return false;
+
+    if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(1)))
+      if (Const->isNegative())
+        return false;
+
     bool NegImm = cast<ConstantInt>(I->getOperand(1))->isNegative();
     bool IsDecreasing = ((Opc == Instruction::Sub) && !NegImm) ||
                         ((Opc == Instruction::Add) && NegImm);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52102.165755.patch
Type: text/x-patch
Size: 1808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180917/0b5cc8b9/attachment.bin>


More information about the llvm-commits mailing list