From 92945eee80d8d39a18b4033f7d589c92e6f50f39 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 30 May 2014 15:00:45 +0000 Subject: [PATCH] [pr19636] Fix known bit computation in urem instruction with power of two. Patch by Andrey Kuharev. llvm-svn: 209902 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 7 +++++-- llvm/test/CodeGen/X86/computeKnownBits_urem.ll | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/X86/computeKnownBits_urem.ll diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 51ae11d..65a3f0a 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2185,8 +2185,11 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero, 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; } } diff --git a/llvm/test/CodeGen/X86/computeKnownBits_urem.ll b/llvm/test/CodeGen/X86/computeKnownBits_urem.ll new file mode 100644 index 0000000..9902e6f --- /dev/null +++ b/llvm/test/CodeGen/X86/computeKnownBits_urem.ll @@ -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 -- 2.7.4