[llvm] a547b4e - Revert "[InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)"

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 7 00:41:05 PDT 2021


I cannot generate a reproducer, for some reason -gen-reproducer gets stuck
as well, but I'm able to reproduce the issue by running:

/src/clang-llvm/llvm-build/fuchsia/./bin/clang++ -DXRAY_HAS_EXCEPTIONS=1
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-I/src/clang-llvm/llvm-project/compiler-rt/lib/xray/..
-I/src/clang-llvm/llvm-project/compiler-rt/lib/xray/../../include -fPIC
-fvisibility-inlines-hidden -ffunction-sections -fdata-sections -std=c++14
-g -DNDEBUG -fno-builtin -fno-exceptions -fomit-frame-pointer
-funwind-tables -fno-stack-protector -fvisibility=hidden -O3
-gline-tables-only -fno-rtti -MD -MT
compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_x86_64.cpp.o -MF
compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_x86_64.cpp.o.d -o
compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_x86_64.cpp.o -c
/src/clang-llvm/llvm-project/compiler-rt/lib/xray/xray_x86_64.cpp

On Wed, Apr 7, 2021 at 12:25 AM Roman Lebedev <lebedev.ri at gmail.com> wrote:

> Reproducer please?
>
> On Wed, Apr 7, 2021 at 8:46 AM Petr Hosek via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> >
> >
> > Author: Petr Hosek
> > Date: 2021-04-06T22:30:28-07:00
> > New Revision: a547b4e26b311e417cd51100e379693f51a3f448
> >
> > URL:
> https://github.com/llvm/llvm-project/commit/a547b4e26b311e417cd51100e379693f51a3f448
> > DIFF:
> https://github.com/llvm/llvm-project/commit/a547b4e26b311e417cd51100e379693f51a3f448.diff
> >
> > LOG: Revert "[InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)`
> (PR49858)"
> >
> > This reverts commit 31d219d2997fed1b7dc97e0adf170d5aaf65883e which
> > causes an infinite loop when compiling the XRay runtime.
> >
> > Added:
> >
> >
> > Modified:
> >     llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> >     llvm/test/Transforms/InstCombine/abs-1.ll
> >     llvm/test/Transforms/InstCombine/sub-from-sub.ll
> >
> > Removed:
> >
> >
> >
> >
> ################################################################################
> > diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> > index 4ced5994ffa6..bacb8689892a 100644
> > --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> > +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> > @@ -1801,12 +1801,6 @@ Instruction
> *InstCombinerImpl::visitSub(BinaryOperator &I) {
> >      return BinaryOperator::CreateSub(XZ, YW);
> >    }
> >
> > -  // ((X - Y) - Op1)  -->  X - (Y + Op1)
> > -  if (match(Op0, m_OneUse(m_Sub(m_Value(X), m_Value(Y))))) {
> > -    Value *Add = Builder.CreateAdd(Y, Op1);
> > -    return BinaryOperator::CreateSub(X, Add);
> > -  }
> > -
> >    auto m_AddRdx = [](Value *&Vec) {
> >      return
> m_OneUse(m_Intrinsic<Intrinsic::vector_reduce_add>(m_Value(Vec)));
> >    };
> >
> > diff  --git a/llvm/test/Transforms/InstCombine/abs-1.ll
> b/llvm/test/Transforms/InstCombine/abs-1.ll
> > index ea77dfb5fef4..7452798ead77 100644
> > --- a/llvm/test/Transforms/InstCombine/abs-1.ll
> > +++ b/llvm/test/Transforms/InstCombine/abs-1.ll
> > @@ -305,9 +305,9 @@ define i32 @nabs_canonical_8(i32 %a) {
> >  define i32 @nabs_canonical_9(i32 %a, i32 %b) {
> >  ; CHECK-LABEL: @nabs_canonical_9(
> >  ; CHECK-NEXT:    [[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
> > +; CHECK-NEXT:    [[T2:%.*]] = sub i32 [[B]], [[A]]
> >  ; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.abs.i32(i32 [[T1]], i1
> false)
> > -; CHECK-NEXT:    [[TMP2:%.*]] = add i32 [[TMP1]], [[A]]
> > -; CHECK-NEXT:    [[ADD:%.*]] = sub i32 [[B]], [[TMP2]]
> > +; CHECK-NEXT:    [[ADD:%.*]] = sub i32 [[T2]], [[TMP1]]
> >  ; CHECK-NEXT:    ret i32 [[ADD]]
> >  ;
> >    %t1 = sub i32 %a, %b
> >
> > diff  --git a/llvm/test/Transforms/InstCombine/sub-from-sub.ll
> b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
> > index aaa8b1db32de..202dbd1072a4 100644
> > --- a/llvm/test/Transforms/InstCombine/sub-from-sub.ll
> > +++ b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
> > @@ -8,8 +8,8 @@ declare void @use8(i8)
> >  ; Basic test
> >  define i8 @t0(i8 %x, i8 %y, i8 %z) {
> >  ; CHECK-LABEL: @t0(
> > -; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[Y:%.*]], [[Z:%.*]]
> > -; CHECK-NEXT:    [[R:%.*]] = sub i8 [[X:%.*]], [[TMP1]]
> > +; CHECK-NEXT:    [[I0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
> > +; CHECK-NEXT:    [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]]
> >  ; CHECK-NEXT:    ret i8 [[R]]
> >  ;
> >    %i0 = sub i8 %x, %y
> > @@ -20,8 +20,8 @@ define i8 @t0(i8 %x, i8 %y, i8 %z) {
> >  ; No flags are propagated
> >  define i8 @t1_flags(i8 %x, i8 %y, i8 %z) {
> >  ; CHECK-LABEL: @t1_flags(
> > -; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[Y:%.*]], [[Z:%.*]]
> > -; CHECK-NEXT:    [[R:%.*]] = sub i8 [[X:%.*]], [[TMP1]]
> > +; CHECK-NEXT:    [[O0:%.*]] = sub nuw nsw i8 [[X:%.*]], [[Y:%.*]]
> > +; CHECK-NEXT:    [[R:%.*]] = sub nuw nsw i8 [[O0]], [[Z:%.*]]
> >  ; CHECK-NEXT:    ret i8 [[R]]
> >  ;
> >    %o0 = sub nuw nsw i8 %x, %y
> > @@ -47,8 +47,8 @@ define i8 @n2(i8 %x, i8 %y, i8 %z) {
> >
> >  define i8 @t3_c0(i8 %y, i8 %z) {
> >  ; CHECK-LABEL: @t3_c0(
> > -; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[Y:%.*]], [[Z:%.*]]
> > -; CHECK-NEXT:    [[R:%.*]] = sub i8 42, [[TMP1]]
> > +; CHECK-NEXT:    [[I0:%.*]] = sub i8 42, [[Y:%.*]]
> > +; CHECK-NEXT:    [[R:%.*]] = sub i8 [[I0]], [[Z:%.*]]
> >  ; CHECK-NEXT:    ret i8 [[R]]
> >  ;
> >    %i0 = sub i8 42, %y
> >
> >
> >
> > _______________________________________________
> > 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/20210407/06ac4e67/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3996 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210407/06ac4e67/attachment.bin>


More information about the llvm-commits mailing list