[llvm] fa154a9 - Revert "Expand Div/Rem: consider the case where the dividend is zero"

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 09:02:30 PDT 2022


Can you take a look at https://reviews.llvm.org/D130680. I hadn't pushed it
yet because the AMDGPU code looked worse. You can take it over if you want.

~Craig


On Thu, Sep 1, 2022 at 8:59 AM Nuno Lopes <nuno.lopes at tecnico.ulisboa.pt>
wrote:

> There were a few test failures in amdgpu codegen. Plus generated assembly
> wasn’t great. I have a better fix that keeps assembly unchanged for x86 at
> least.
>
>
>
> Nuno
>
>
>
>
>
> *From:* Craig Topper <craig.topper at gmail.com>
> *Sent:* Thursday, September 1, 2022 4:47 PM
> *To:* Nuno Lopes <nuno.lopes at tecnico.ulisboa.pt>; Nuno Lopes <
> llvmlistbot at llvm.org>
> *Cc:* llvm-commits <llvm-commits at lists.llvm.org>
> *Subject:* Re: [llvm] fa154a9 - Revert "Expand Div/Rem: consider the case
> where the dividend is zero"
>
>
>
> Why was it reverted?
>
>
> ~Craig
>
>
>
>
>
> On Thu, Sep 1, 2022 at 4:11 AM Nuno Lopes via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>
> Author: Nuno Lopes
> Date: 2022-09-01T12:11:22+01:00
> New Revision: fa154a9170573e3a17639d0f71b5bccade8f7be9
>
> URL:
> https://github.com/llvm/llvm-project/commit/fa154a9170573e3a17639d0f71b5bccade8f7be9
> DIFF:
> https://github.com/llvm/llvm-project/commit/fa154a9170573e3a17639d0f71b5bccade8f7be9.diff
>
> LOG: Revert "Expand Div/Rem: consider the case where the dividend is zero"
>
> This reverts commit 4aed09868b5a51a29aade11d9d412c3313310f29.
>
> Added:
>
>
> Modified:
>     llvm/lib/Transforms/Utils/IntegerDivision.cpp
>     llvm/test/Transforms/ExpandLargeDivRem/sdiv129.ll
>     llvm/test/Transforms/ExpandLargeDivRem/srem129.ll
>     llvm/test/Transforms/ExpandLargeDivRem/udiv129.ll
>     llvm/test/Transforms/ExpandLargeDivRem/urem129.ll
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/Transforms/Utils/IntegerDivision.cpp
> b/llvm/lib/Transforms/Utils/IntegerDivision.cpp
> index 52a175b4c87c8..1267360b34b18 100644
> --- a/llvm/lib/Transforms/Utils/IntegerDivision.cpp
> +++ b/llvm/lib/Transforms/Utils/IntegerDivision.cpp
> @@ -148,7 +148,6 @@ static Value *generateUnsignedDivisionCode(Value
> *Dividend, Value *Divisor,
>    ConstantInt *MSB = ConstantInt::get(DivTy, BitWidth - 1);
>
>    ConstantInt *True = Builder.getTrue();
> -  ConstantInt *False = Builder.getFalse();
>
>    BasicBlock *IBB = Builder.GetInsertBlock();
>    Function *F = IBB->getParent();
> @@ -212,8 +211,8 @@ static Value *generateUnsignedDivisionCode(Value
> *Dividend, Value *Divisor,
>    // ;   %ret0_2      = icmp eq i32 %dividend, 0
>    // ;   %ret0_3      = or i1 %ret0_1, %ret0_2
>    // ;   %tmp0        = tail call i32 @llvm.ctlz.i32(i32 %divisor, i1
> true)
> -  // ;   %tmp1        = tail call i32 @llvm.ctlz.i32(i32 %dividend, i1
> false)
> -  // ;   %sr          = sub i32 %tmp0, %tmp1
> +  // ;   %tmp1        = tail call i32 @llvm.ctlz.i32(i32 %dividend, i1
> true)
> +  // ;   %sr          = sub nsw i32 %tmp0, %tmp1
>    // ;   %ret0_4      = icmp ugt i32 %sr, 31
>    // ;   %ret0        = or i1 %ret0_3, %ret0_4
>    // ;   %retDividend = icmp eq i32 %sr, 31
> @@ -225,7 +224,7 @@ static Value *generateUnsignedDivisionCode(Value
> *Dividend, Value *Divisor,
>    Value *Ret0_2      = Builder.CreateICmpEQ(Dividend, Zero);
>    Value *Ret0_3      = Builder.CreateOr(Ret0_1, Ret0_2);
>    Value *Tmp0 = Builder.CreateCall(CTLZ, {Divisor, True});
> -  Value *Tmp1 = Builder.CreateCall(CTLZ, {Dividend, False});
> +  Value *Tmp1 = Builder.CreateCall(CTLZ, {Dividend, True});
>    Value *SR          = Builder.CreateSub(Tmp0, Tmp1);
>    Value *Ret0_4      = Builder.CreateICmpUGT(SR, MSB);
>    Value *Ret0        = Builder.CreateOr(Ret0_3, Ret0_4);
>
> diff  --git a/llvm/test/Transforms/ExpandLargeDivRem/sdiv129.ll
> b/llvm/test/Transforms/ExpandLargeDivRem/sdiv129.ll
> index 2bfad7b6fa839..27ab1e8eb9ed6 100644
> --- a/llvm/test/Transforms/ExpandLargeDivRem/sdiv129.ll
> +++ b/llvm/test/Transforms/ExpandLargeDivRem/sdiv129.ll
> @@ -12,7 +12,7 @@ define void @sdiv129(i129* %ptr, i129* %out) nounwind {
>  ; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i129 [[TMP2]], 0
>  ; CHECK-NEXT:    [[TMP5:%.*]] = or i1 false, [[TMP4]]
>  ; CHECK-NEXT:    [[TMP6:%.*]] = call i129 @llvm.ctlz.i129(i129 3, i1 true)
> -; CHECK-NEXT:    [[TMP7:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP2]],
> i1 false)
> +; CHECK-NEXT:    [[TMP7:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP2]],
> i1 true)
>  ; CHECK-NEXT:    [[TMP8:%.*]] = sub i129 [[TMP6]], [[TMP7]]
>  ; CHECK-NEXT:    [[TMP9:%.*]] = icmp ugt i129 [[TMP8]], 128
>  ; CHECK-NEXT:    [[TMP10:%.*]] = or i1 [[TMP5]], [[TMP9]]
>
> diff  --git a/llvm/test/Transforms/ExpandLargeDivRem/srem129.ll
> b/llvm/test/Transforms/ExpandLargeDivRem/srem129.ll
> index c4326333786fe..08df750a13663 100644
> --- a/llvm/test/Transforms/ExpandLargeDivRem/srem129.ll
> +++ b/llvm/test/Transforms/ExpandLargeDivRem/srem129.ll
> @@ -11,7 +11,7 @@ define void @test(i129* %ptr, i129* %out) nounwind {
>  ; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i129 [[TMP2]], 0
>  ; CHECK-NEXT:    [[TMP4:%.*]] = or i1 false, [[TMP3]]
>  ; CHECK-NEXT:    [[TMP5:%.*]] = call i129 @llvm.ctlz.i129(i129 3, i1 true)
> -; CHECK-NEXT:    [[TMP6:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP2]],
> i1 false)
> +; CHECK-NEXT:    [[TMP6:%.*]] = call i129 @llvm.ctlz.i129(i129 [[TMP2]],
> i1 true)
>  ; CHECK-NEXT:    [[TMP7:%.*]] = sub i129 [[TMP5]], [[TMP6]]
>  ; CHECK-NEXT:    [[TMP8:%.*]] = icmp ugt i129 [[TMP7]], 128
>  ; CHECK-NEXT:    [[TMP9:%.*]] = or i1 [[TMP4]], [[TMP8]]
>
> diff  --git a/llvm/test/Transforms/ExpandLargeDivRem/udiv129.ll
> b/llvm/test/Transforms/ExpandLargeDivRem/udiv129.ll
> index 1929963331913..31705a9a35c10 100644
> --- a/llvm/test/Transforms/ExpandLargeDivRem/udiv129.ll
> +++ b/llvm/test/Transforms/ExpandLargeDivRem/udiv129.ll
> @@ -8,7 +8,7 @@ define void @test(i129* %ptr, i129* %out) nounwind {
>  ; CHECK-NEXT:    [[TMP0:%.*]] = icmp eq i129 [[A]], 0
>  ; CHECK-NEXT:    [[TMP1:%.*]] = or i1 false, [[TMP0]]
>  ; CHECK-NEXT:    [[TMP2:%.*]] = call i129 @llvm.ctlz.i129(i129 3, i1 true)
> -; CHECK-NEXT:    [[TMP3:%.*]] = call i129 @llvm.ctlz.i129(i129 [[A]], i1
> false)
> +; CHECK-NEXT:    [[TMP3:%.*]] = call i129 @llvm.ctlz.i129(i129 [[A]], i1
> true)
>  ; CHECK-NEXT:    [[TMP4:%.*]] = sub i129 [[TMP2]], [[TMP3]]
>  ; CHECK-NEXT:    [[TMP5:%.*]] = icmp ugt i129 [[TMP4]], 128
>  ; CHECK-NEXT:    [[TMP6:%.*]] = or i1 [[TMP1]], [[TMP5]]
>
> diff  --git a/llvm/test/Transforms/ExpandLargeDivRem/urem129.ll
> b/llvm/test/Transforms/ExpandLargeDivRem/urem129.ll
> index 36ecb990e52f5..4e91eef6d2aa6 100644
> --- a/llvm/test/Transforms/ExpandLargeDivRem/urem129.ll
> +++ b/llvm/test/Transforms/ExpandLargeDivRem/urem129.ll
> @@ -8,7 +8,7 @@ define void @test(i129* %ptr, i129* %out) nounwind {
>  ; CHECK-NEXT:    [[TMP0:%.*]] = icmp eq i129 [[A]], 0
>  ; CHECK-NEXT:    [[TMP1:%.*]] = or i1 false, [[TMP0]]
>  ; CHECK-NEXT:    [[TMP2:%.*]] = call i129 @llvm.ctlz.i129(i129 3, i1 true)
> -; CHECK-NEXT:    [[TMP3:%.*]] = call i129 @llvm.ctlz.i129(i129 [[A]], i1
> false)
> +; CHECK-NEXT:    [[TMP3:%.*]] = call i129 @llvm.ctlz.i129(i129 [[A]], i1
> true)
>  ; CHECK-NEXT:    [[TMP4:%.*]] = sub i129 [[TMP2]], [[TMP3]]
>  ; CHECK-NEXT:    [[TMP5:%.*]] = icmp ugt i129 [[TMP4]], 128
>  ; CHECK-NEXT:    [[TMP6:%.*]] = or i1 [[TMP1]], [[TMP5]]
>
>
>
> _______________________________________________
> 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/20220901/fb466c51/attachment.html>


More information about the llvm-commits mailing list