[PATCH] Fix urem instruction with power of two to compute known bit.
Andrey Kuharev
an.kuharev at gmail.com
Tue May 20 03:49:07 PDT 2014
http://reviews.llvm.org/D3823
Files:
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
test/CodeGen/Generic/computeKnownBits_urem.ll
Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2188,20 +2188,22 @@
}
break;
case ISD::UREM: {
+ bool IsConstPowerOf2 = false;
if (ConstantSDNode *Rem = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
const APInt &RA = Rem->getAPIntValue();
if (RA.isPowerOf2()) {
APInt LowBits = (RA - 1);
KnownZero |= ~LowBits;
- computeKnownBits(Op.getOperand(0), KnownZero, KnownOne,Depth+1);
- break;
+ computeKnownBits(Op.getOperand(0), KnownZero2, KnownOne2,Depth+1);
+ IsConstPowerOf2 = true;
}
}
-
- // Since the result is less than or equal to either operand, any leading
- // zero bits in either operand must also exist in the result.
- computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1);
- computeKnownBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1);
+ if (!IsConstPowerOf2) {
+ // Since the result is less than or equal to either operand, any leading
+ // zero bits in either operand must also exist in the result.
+ computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1);
+ computeKnownBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1);
+ }
uint32_t Leaders = std::max(KnownZero.countLeadingOnes(),
KnownZero2.countLeadingOnes());
Index: test/CodeGen/Generic/computeKnownBits_urem.ll
===================================================================
--- test/CodeGen/Generic/computeKnownBits_urem.ll
+++ test/CodeGen/Generic/computeKnownBits_urem.ll
@@ -0,0 +1,14 @@
+; RUN: llc -debug %s -o /dev/null 2>&1 | 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: Replacing.2 0x{{[0-9a-f]+}}: i32 = urem 0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}} [ORD=7]
+; CHECK: With: 0x{{[0-9a-f]+}}: i32 = Constant<0>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3823.9604.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140520/7b98bd6d/attachment.bin>
More information about the llvm-commits
mailing list