[llvm] r209902 - [pr19636] Fix known bit computation in urem instruction with power of two.

Rafael Espindola rafael.espindola at gmail.com
Fri May 30 08:00:45 PDT 2014


Author: rafael
Date: Fri May 30 10:00:45 2014
New Revision: 209902

URL: http://llvm.org/viewvc/llvm-project?rev=209902&view=rev
Log:
[pr19636]  Fix known bit computation in urem instruction with power of two.
Patch by Andrey Kuharev.

Added:
    llvm/trunk/test/CodeGen/X86/computeKnownBits_urem.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=209902&r1=209901&r2=209902&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri May 30 10:00:45 2014
@@ -2185,8 +2185,11 @@ void SelectionDAG::computeKnownBits(SDVa
       const APInt &RA = Rem->getAPIntValue();
       if (RA.isPowerOf2()) {
         APInt LowBits = (RA - 1);
-        KnownZero |= ~LowBits;
-        computeKnownBits(Op.getOperand(0), KnownZero, KnownOne,Depth+1);
+        computeKnownBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth + 1);
+
+        // The upper bits are all zero, the lower ones are unchanged.
+        KnownZero = KnownZero2 | ~LowBits;
+        KnownOne = KnownOne2 & LowBits;
         break;
       }
     }

Added: llvm/trunk/test/CodeGen/X86/computeKnownBits_urem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/computeKnownBits_urem.ll?rev=209902&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/computeKnownBits_urem.ll (added)
+++ llvm/trunk/test/CodeGen/X86/computeKnownBits_urem.ll Fri May 30 10:00:45 2014
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
+define i32 @main() #0 {
+entry:
+  %a = alloca i32, align 4
+  store i32 1, i32* %a, align 4
+  %0 = load i32* %a, align 4
+  %or = or i32 1, %0
+  %and = and i32 1, %or
+  %rem = urem i32 %and, 1
+  %add = add i32 %rem, 1
+  ret i32 %add
+}
+; CHECK: $1, %eax
+; CHECK-NEXT: retq





More information about the llvm-commits mailing list