[llvm] r206834 - [CodeGenPrepare] Use APInt to check the value of the immediate in a and

Quentin Colombet qcolombet at apple.com
Mon Apr 21 18:20:35 PDT 2014


Author: qcolombet
Date: Mon Apr 21 20:20:34 2014
New Revision: 206834

URL: http://llvm.org/viewvc/llvm-project?rev=206834&view=rev
Log:
[CodeGenPrepare] Use APInt to check the value of the immediate in a and
while checking candidate for bit field extract.
Otherwise the value may not fit in uint64_t and this will trigger an
assertion.

This fixes PR19503.

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/test/CodeGen/ARM64/bitfield-extract.ll

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=206834&r1=206833&r2=206834&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Mon Apr 21 20:20:34 2014
@@ -639,9 +639,9 @@ bool isExtractBitsCandidateUse(Instructi
         !isa<ConstantInt>(User->getOperand(1)))
       return false;
 
-    unsigned Cimm = dyn_cast<ConstantInt>(User->getOperand(1))->getZExtValue();
+    const APInt &Cimm = cast<ConstantInt>(User->getOperand(1))->getValue();
 
-    if (Cimm & (Cimm + 1))
+    if ((Cimm & (Cimm + 1)).getBoolValue())
       return false;
   }
   return true;

Modified: llvm/trunk/test/CodeGen/ARM64/bitfield-extract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM64/bitfield-extract.ll?rev=206834&r1=206833&r2=206834&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM64/bitfield-extract.ll (original)
+++ llvm/trunk/test/CodeGen/ARM64/bitfield-extract.ll Mon Apr 21 20:20:34 2014
@@ -477,3 +477,26 @@ return:
   %retval.0 = phi i32 [ %conv, %if.then ], [ %add, %if.then7 ], [ %add23, %if.then17 ], [ 64, %if.end13 ]
   ret i32 %retval.0
 }
+
+; Make sure we do not assert if the immediate in and is bigger than i64.
+; PR19503.
+; OPT-LABEL: @fct20
+; OPT: lshr
+; OPT-NOT: lshr
+; OPT: ret
+; CHECK-LABEL: fct20:
+; CHECK: ret
+define i80 @fct20(i128 %a, i128 %b) {
+entry:
+  %shr = lshr i128 %a, 18
+  %conv = trunc i128 %shr to i80
+  %tobool = icmp eq i128 %b, 0
+  br i1 %tobool, label %then, label %end
+then:                     
+  %and = and i128 %shr, 483673642326615442599424
+  %conv2 = trunc i128 %and to i80
+  br label %end
+end:
+  %conv3 = phi i80 [%conv, %entry], [%conv2, %then] 
+  ret i80 %conv3
+}





More information about the llvm-commits mailing list