[llvm] 673a467 - [ConstantFold] Avoid creation of undesirable binop

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 14:07:22 PDT 2023


It was reverted with 9eb73f9c9d409f35151b0c1e01f1ed95808acd0c because of
LTO, but
also it fails assert on
https://lab.llvm.org/buildbot/#/builders/237/builds/3711/steps/12/logs/stdio

On Tue, 25 Jul 2023 at 07:55, Nikita Popov via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Nikita Popov
> Date: 2023-07-25T16:54:57+02:00
> New Revision: 673a4671f3e8b7158d990f6456428175a6eac38c
>
> URL:
> https://github.com/llvm/llvm-project/commit/673a4671f3e8b7158d990f6456428175a6eac38c
> DIFF:
> https://github.com/llvm/llvm-project/commit/673a4671f3e8b7158d990f6456428175a6eac38c.diff
>
> LOG: [ConstantFold] Avoid creation of undesirable binop
>
> When commuting the operands, don't create a constant expression
> for undesirable binops. Only invoke the constant folding function
> in that case.
>
> Added:
>
>
> Modified:
>     llvm/lib/IR/ConstantFold.cpp
>     llvm/test/Transforms/InstCombine/pr32686.ll
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
> index 40b21876281142..04e4217beb0884 100644
> --- a/llvm/lib/IR/ConstantFold.cpp
> +++ b/llvm/lib/IR/ConstantFold.cpp
> @@ -1084,7 +1084,9 @@ Constant
> *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
>    } else if (isa<ConstantInt>(C1)) {
>      // If C1 is a ConstantInt and C2 is not, swap the operands.
>      if (Instruction::isCommutative(Opcode))
> -      return ConstantExpr::get(Opcode, C2, C1);
> +      return ConstantExpr::isDesirableBinOp(Opcode)
> +                 ? ConstantExpr::get(Opcode, C2, C1)
> +                 : ConstantFoldBinaryInstruction(Opcode, C2, C1);
>    }
>
>    if (ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
>
> diff  --git a/llvm/test/Transforms/InstCombine/pr32686.ll
> b/llvm/test/Transforms/InstCombine/pr32686.ll
> index acce81a603d2d0..f981065bebeb80 100644
> --- a/llvm/test/Transforms/InstCombine/pr32686.ll
> +++ b/llvm/test/Transforms/InstCombine/pr32686.ll
> @@ -8,8 +8,9 @@ define void @tinkywinky() {
>  ; CHECK-LABEL: @tinkywinky(
>  ; CHECK-NEXT:    [[PATATINO:%.*]] = load i8, ptr @a, align 1
>  ; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq i8 [[PATATINO]], 0
> -; CHECK-NEXT:    [[TMP1:%.*]] = zext i1 [[TOBOOL_NOT]] to i32
> -; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[TMP1]], or (i32 zext (i1 icmp ne
> (ptr @a, ptr @b) to i32), i32 2)
> +; CHECK-NEXT:    [[TMP1:%.*]] = or i1 [[TOBOOL_NOT]], icmp ne (ptr @a,
> ptr @b)
> +; CHECK-NEXT:    [[TMP2:%.*]] = zext i1 [[TMP1]] to i32
> +; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[TMP2]], 2
>  ; CHECK-NEXT:    store i32 [[OR1]], ptr @b, align 4
>  ; CHECK-NEXT:    ret void
>  ;
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/8fe87782/attachment.html>


More information about the llvm-commits mailing list