[PATCH] Fix big shift constant folding

Paweł Bylica chfast at gmail.com
Wed Feb 18 13:06:03 PST 2015


How can I find reviewers for the change?

On Tue Feb 17 2015 at 9:14:39 PM Paweł Bylica <chfast at gmail.com> wrote:

> Constant folding for shift IR instructions ignores all bits above 32 of
> second argument (shift amount). Because of that, some undef results are not
> recognized and APInt can raise an assert failure if second argument has
> more than 64 bits.
>
> REPOSITORY
>   rL LLVM
>
> http://reviews.llvm.org/D7701
>
> Files:
>   lib/IR/ConstantFold.cpp
>
> Index: lib/IR/ConstantFold.cpp
> ===================================================================
> --- lib/IR/ConstantFold.cpp
> +++ lib/IR/ConstantFold.cpp
> @@ -1120,27 +1120,18 @@
>          return ConstantInt::get(CI1->getContext(), C1V | C2V);
>        case Instruction::Xor:
>          return ConstantInt::get(CI1->getContext(), C1V ^ C2V);
> -      case Instruction::Shl: {
> -        uint32_t shiftAmt = C2V.getZExtValue();
> -        if (shiftAmt < C1V.getBitWidth())
> -          return ConstantInt::get(CI1->getContext(), C1V.shl(shiftAmt));
> -        else
> +      case Instruction::Shl:
> +        if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >=
> C1V.getBitWidth())
>            return UndefValue::get(C1->getType()); // too big shift is
> undef
> -      }
> -      case Instruction::LShr: {
> -        uint32_t shiftAmt = C2V.getZExtValue();
> -        if (shiftAmt < C1V.getBitWidth())
> -          return ConstantInt::get(CI1->getContext(), C1V.lshr(shiftAmt));
> -        else
> +        return ConstantInt::get(CI1->getContext(),
> C1V.shl(C2V.getZExtValue()));
> +      case Instruction::LShr:
> +        if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >=
> C1V.getBitWidth())
>            return UndefValue::get(C1->getType()); // too big shift is
> undef
> -      }
> -      case Instruction::AShr: {
> -        uint32_t shiftAmt = C2V.getZExtValue();
> -        if (shiftAmt < C1V.getBitWidth())
> -          return ConstantInt::get(CI1->getContext(), C1V.ashr(shiftAmt));
> -        else
> +        return ConstantInt::get(CI1->getContext(),
> C1V.lshr(C2V.getZExtValue()));
> +      case Instruction::AShr:
> +        if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >=
> C1V.getBitWidth())
>            return UndefValue::get(C1->getType()); // too big shift is
> undef
> -      }
> +        return ConstantInt::get(CI1->getContext(),
> C1V.ashr(C2V.getZExtValue()));
>        }
>      }
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150218/e71e012a/attachment.html>


More information about the llvm-commits mailing list