[llvm-branch-commits] [mlir] a16c00a - [mlir][python] Fix python extension building on windows.

2020-12-31 Thread Stella Laurenzo via llvm-branch-commits

Author: Stella Laurenzo
Date: 2020-12-31T00:11:39-08:00
New Revision: a16c00a7033df6863f3ecd77a9809790f8db286b

URL: 
https://github.com/llvm/llvm-project/commit/a16c00a7033df6863f3ecd77a9809790f8db286b
DIFF: 
https://github.com/llvm/llvm-project/commit/a16c00a7033df6863f3ecd77a9809790f8db286b.diff

LOG: [mlir][python] Fix python extension building on windows.

Added: 


Modified: 
mlir/cmake/modules/AddMLIRPythonExtension.cmake

Removed: 




diff  --git a/mlir/cmake/modules/AddMLIRPythonExtension.cmake 
b/mlir/cmake/modules/AddMLIRPythonExtension.cmake
index eaba5214b5a8..290b4a23aa31 100644
--- a/mlir/cmake/modules/AddMLIRPythonExtension.cmake
+++ b/mlir/cmake/modules/AddMLIRPythonExtension.cmake
@@ -44,6 +44,10 @@ function(add_mlir_python_extension libname extname)
 "${pybind11_INCLUDE_DIR}"
   )
 
+  target_link_directories(${libname} PRIVATE
+"${Python3_LIBRARY_DIRS}"
+  )
+
   # The extension itself must be compiled with RTTI and exceptions enabled.
   # Also, some warning classes triggered by pybind11 are disabled.
   target_compile_options(${libname} PRIVATE



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] f2cc266 - [test] Fix -triple and delete UNSUPPORTED: system-windows

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T00:13:34-08:00
New Revision: f2cc2669a0d91994c93f2e9708e137484081a7c1

URL: 
https://github.com/llvm/llvm-project/commit/f2cc2669a0d91994c93f2e9708e137484081a7c1
DIFF: 
https://github.com/llvm/llvm-project/commit/f2cc2669a0d91994c93f2e9708e137484081a7c1.diff

LOG: [test] Fix -triple and delete UNSUPPORTED: system-windows

Added: 


Modified: 
clang/test/CodeGen/attr-loader-uninitialized.c
clang/test/CodeGenCXX/attr-loader-uninitialized.cpp

Removed: 




diff  --git a/clang/test/CodeGen/attr-loader-uninitialized.c 
b/clang/test/CodeGen/attr-loader-uninitialized.c
index 9ff0c23d77c3..eecd1eaf221d 100644
--- a/clang/test/CodeGen/attr-loader-uninitialized.c
+++ b/clang/test/CodeGen/attr-loader-uninitialized.c
@@ -1,5 +1,4 @@
-// UNSUPPORTED: system-windows
-// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
 
 // CHECK: @tentative_attr_first = global i32 undef
 int tentative_attr_first __attribute__((loader_uninitialized));

diff  --git a/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp 
b/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
index ec3e84b59023..1542b39e1159 100644
--- a/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
+++ b/clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -1,5 +1,4 @@
-// UNSUPPORTED: system-windows
-// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
 
 // CHECK: @defn = global i32 undef
 int defn  [[clang::loader_uninitialized]];



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] a92d015 - [sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature detection and support musl

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T00:44:25-08:00
New Revision: a92d01534f1c4fb79210975573e774d0393f2533

URL: 
https://github.com/llvm/llvm-project/commit/a92d01534f1c4fb79210975573e774d0393f2533
DIFF: 
https://github.com/llvm/llvm-project/commit/a92d01534f1c4fb79210975573e774d0393f2533.diff

LOG: [sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature 
detection and support musl

Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are replaced
with the more appropriate `#if SANITIZER_GLIBC` (the headers are glibc
extensions, not specific to Linux (i.e. if we ever support GNU/kFreeBSD
or Hurd, the guards may automatically work)).

Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are refined
with `#if SANITIZER_GLIBC` (the definitions are available on Linux glibc,
but may not be available on other libc (e.g. musl) implementations).

This patch makes `ninja asan cfi msan stats tsan ubsan xray` build on a musl 
based Linux distribution (apk install musl-libintl)
Notes about disabled interceptors for musl:

* `SANITIZER_INTERCEPT_GLOB`: musl does not implement `GLOB_ALTDIRFUNC` (GNU 
extension)
* Some ioctl structs and functions operating on them.
* `SANITIZER_INTERCEPT___PRINTF_CHK`: `_FORTIFY_SOURCE` functions are GNU 
extension
* `SANITIZER_INTERCEPT___STRNDUP`: `dlsym(RTLD_NEXT, "__strndup")` errors so a 
diagnostic is formed. The diagnostic uses `write` which hasn't been intercepted 
=> SIGSEGV
* `SANITIZER_INTERCEPT_*64`: the `_LARGEFILE64_SOURCE` functions are glibc 
specific. musl does something like `#define pread64 pread`
* Disabled `msg_iovlen msg_controllen cmsg_len` checks: musl is conforming 
while many implementations (Linux/FreeBSD/NetBSD/Solaris) are non-conforming. 
Since we pick the glibc definition, exclude the checks for musl (incompatible 
sizes but compatible offsets)

Pass through LIBCXX_HAS_MUSL_LIBC to make check-msan/check-tsan able to build 
libc++ (https://bugs.llvm.org/show_bug.cgi?id=48618).

Many sanitizer features are available now.

```
% ninja check-asan
(known issues:
* ASAN_OPTIONS=fast_unwind_on_malloc=0 odr-violations hangs
)
...
Testing Time: 53.69s
  Unsupported  : 185
  Passed   : 512
  Expectedly Failed:   1
  Failed   :  12

% ninja check-ubsan check-ubsan-minimal check-memprof # all passed

% ninja check-cfi
( all cross-dso/)
...
Testing Time: 8.68s
  Unsupported  : 264
  Passed   :  80
  Expectedly Failed:   8
  Failed   :  32

% ninja check-msan
(Many are due to functions not marked unsupported.)
Testing Time: 23.09s
  Unsupported  :   6
  Passed   : 764
  Expectedly Failed:   2
  Failed   :  58

% ninja check-tsan
Testing Time: 23.21s
  Unsupported  :  86
  Passed   : 295
  Expectedly Failed:   1
  Failed   :  25
```

Used `ASAN_OPTIONS=verbosity=2` to verify no unneeded interceptors.

Partly based on Jari Ronkainen's https://reviews.llvm.org/D63785#1921014

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D93848

Added: 


Modified: 
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/lib/asan/asan_interceptors.h
compiler-rt/lib/asan/tests/asan_test.cpp
compiler-rt/lib/interception/interception_linux.cpp
compiler-rt/lib/interception/interception_linux.h
compiler-rt/lib/msan/tests/msan_test.cpp
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Removed: 




diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index 0b8db6a868a1..361538a58e47 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -583,6 +583,7 @@ macro(add_custom_libcxx name prefix)
 CMAKE_OBJDUMP
 CMAKE_STRIP
 CMAKE_SYSROOT
+LIBCXX_HAS_MUSL_LIBC
 PYTHON_EXECUTABLE
 Python3_EXECUTABLE
 Python2_EXECUTABLE

diff  --git a/compiler-rt/lib/asan/asan_interceptors.h 
b/compiler-rt/lib/asan/asan_interceptors.h
index 4266a31cecb9..45cdb80b1b64 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -60,7 +60,7 @@ void InitializePlatformInterceptors();
 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
 #endif
 
-#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_SOLARIS
+#if SANITIZER_GLIBC || SANITIZER_SOLARIS
 # define ASAN_INTERCEPT_SWAPCONTEXT 1
 #else
 # define ASAN_INTERCEPT_SWAPCONTEXT 0
@@ -72,7 +72,7 @@ void InitializePlatformInterceptors();

[llvm-branch-commits] [compiler-rt] 52d7e18 - [sanitizer] Include fstab.h on glibc/FreeBSD/NetBSD/macOS

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T00:55:58-08:00
New Revision: 52d7e183bf25ea38e1149e39e19d21e6212e701f

URL: 
https://github.com/llvm/llvm-project/commit/52d7e183bf25ea38e1149e39e19d21e6212e701f
DIFF: 
https://github.com/llvm/llvm-project/commit/52d7e183bf25ea38e1149e39e19d21e6212e701f.diff

LOG: [sanitizer] Include fstab.h on glibc/FreeBSD/NetBSD/macOS

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Removed: 




diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index b8f4fcd72644..957653dbbb7c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -159,6 +159,8 @@ typedef struct user_fpregs elf_fpregset_t;
 #include 
 #include 
 #include 
+#else
+#include 
 #endif // SANITIZER_LINUX
 
 #if SANITIZER_MAC
@@ -205,9 +207,9 @@ namespace __sanitizer {
   unsigned struct_statfs64_sz = sizeof(struct statfs64);
 #endif // (SANITIZER_MAC && !TARGET_CPU_ARM64) && !SANITIZER_IOS
 
-#if SANITIZER_GLIBC
+#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_MAC
   unsigned struct_fstab_sz = sizeof(struct fstab);
-#endif  // SANITIZER_GLIBC
+#endif  // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || 
SANITIZER_MAC
 #if !SANITIZER_ANDROID
   unsigned struct_statfs_sz = sizeof(struct statfs);
   unsigned struct_sockaddr_sz = sizeof(struct sockaddr);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] f760d57 - LangRef: fix significand bits of fp128

2020-12-31 Thread Nuno Lopes via llvm-branch-commits

Author: Nuno Lopes
Date: 2020-12-31T11:13:25Z
New Revision: f760d57052d8d16de9679f6c65149005515ead97

URL: 
https://github.com/llvm/llvm-project/commit/f760d57052d8d16de9679f6c65149005515ead97
DIFF: 
https://github.com/llvm/llvm-project/commit/f760d57052d8d16de9679f6c65149005515ead97.diff

LOG: LangRef: fix significand bits of fp128

Added: 


Modified: 
llvm/docs/LangRef.rst

Removed: 




diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 3db5879129ae..ab5287014683 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3070,7 +3070,7 @@ Floating-Point Types
  - 64-bit floating-point value
 
* - ``fp128``
- - 128-bit floating-point value (112-bit significand)
+ - 128-bit floating-point value (113-bit significand)
 
* - ``x86_fp80``
  -  80-bit floating-point value (X87)



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] be76406 - Revert "[ThinLTO][test] Add visibility related tests"

2020-12-31 Thread Shaurya Gupta via llvm-branch-commits

Author: Bogdan Graur
Date: 2020-12-31T11:42:58Z
New Revision: be764065beb2436cf32ca62c9c6148453d6a5814

URL: 
https://github.com/llvm/llvm-project/commit/be764065beb2436cf32ca62c9c6148453d6a5814
DIFF: 
https://github.com/llvm/llvm-project/commit/be764065beb2436cf32ca62c9c6148453d6a5814.diff

LOG: Revert "[ThinLTO][test] Add visibility related tests"

Both newly added tests fail in Release.

This reverts commit 52aa4e210744361a5ed6dc50fef78ed91706e508.

Reviewed By: SureYeaah

Differential Revision: https://reviews.llvm.org/D93957

Added: 


Modified: 


Removed: 
llvm/test/ThinLTO/X86/visibility-elf.ll
llvm/test/ThinLTO/X86/visibility-macho.ll



diff  --git a/llvm/test/ThinLTO/X86/visibility-elf.ll 
b/llvm/test/ThinLTO/X86/visibility-elf.ll
deleted file mode 100644
index 8b2e36afcac6..
--- a/llvm/test/ThinLTO/X86/visibility-elf.ll
+++ /dev/null
@@ -1,137 +0,0 @@
-; RUN: split-file %s %t
-; RUN: opt -module-summary %t/a.ll -o %ta.bc
-; RUN: opt -module-summary %t/b.ll -o %tb.bc
-
-;; Test visibility propagation. The prevailing definitions are all from %tb.bc.
-; RUN: llvm-lto2 run -save-temps -o %t1.bc %ta.bc %tb.bc \
-; RUN:   -r=%ta.bc,var1,l -r=%ta.bc,var2,l \
-; RUN:   -r=%ta.bc,hidden_def_weak_def,l -r=%ta.bc,protected_def_weak_def,l 
-r=%ta.bc,protected_def_weak_hidden_def,l \
-; RUN:   -r=%ta.bc,protected_def_hidden_ref,l -r=%ta.bc,not_imported,l 
-r=%ta.bc,hidden_def_ref,l \
-; RUN:   -r=%ta.bc,hidden_def_weak_ref,l \
-; RUN:   -r=%ta.bc,ext, -r=%ta.bc,main,plx \
-; RUN:   -r=%tb.bc,var1,plx -r=%tb.bc,var2,plx \
-; RUN:   -r=%tb.bc,hidden_def_weak_def,pl -r=%tb.bc,protected_def_weak_def,pl 
-r=%tb.bc,protected_def_weak_hidden_def,pl \
-; RUN:   -r=%tb.bc,protected_def_hidden_ref,pl -r=%tb.bc,not_imported,pl 
-r=%tb.bc,hidden_def_ref,pl \
-; RUN:   -r=%tb.bc,hidden_def_weak_ref,pl
-; RUN: llvm-dis < %t1.bc.1.3.import.bc | FileCheck %s
-
-;; %tb.bc does not import anything, so we just check 1.promote.
-; RUN: llvm-dis < %t1.bc.2.1.promote.bc | FileCheck %s --check-prefix=CHECK2
-
-;--- a.ll
-target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-; CHECK:  @var1 = external global i32, align 4
-; CHECK-NEXT: @var2 = available_externally hidden global i32 1, align 4
-
-@var1 = weak global i32 1, align 4
-@var2 = extern_weak global i32
-
-declare void @ext(void ()*)
-
-; CHECK: declare i32 @hidden_def_weak_def()
-; CHECK: declare void @protected_def_weak_def()
-; CHECK: declare hidden void @protected_def_weak_hidden_def()
-;; Currently the visibility is not propagated onto an unimported function,
-;; because we don't have summaries for declarations.
-; CHECK: declare extern_weak void @not_imported()
-; CHECK: define available_externally hidden void @hidden_def_ref() 
!thinlto_src_module !0
-; CHECK: define available_externally hidden void @hidden_def_weak_ref() 
!thinlto_src_module !0
-;; This can be hidden, but we cannot communicate the declaration's visibility
-;; to other modules because declarations don't have summaries, and the IRLinker
-;; overrides it when importing the protected def.
-; CHECK: define available_externally protected void 
@protected_def_hidden_ref() !thinlto_src_module !0
-
-; CHECK2: define hidden i32 @hidden_def_weak_def()
-; CHECK2: define protected void @protected_def_weak_def()
-; CHECK2: define protected void @protected_def_weak_hidden_def()
-; CHECK2: define hidden void @hidden_def_ref()
-; CHECK2: define hidden void @hidden_def_weak_ref()
-; CHECK2: define protected void @protected_def_hidden_ref()
-; CHECK2: define hidden void @not_imported()
-
-define weak i32 @hidden_def_weak_def() {
-entry:
-  %0 = load i32, i32* @var2
-  ret i32 %0
-}
-
-define weak void @protected_def_weak_def() {
-entry:
-  ret void
-}
-
-define weak hidden void @protected_def_weak_hidden_def() {
-entry:
-  ret void
-}
-
-declare extern_weak void @not_imported()
-
-declare void @hidden_def_ref()
-declare extern_weak void @hidden_def_weak_ref()
-declare hidden void @protected_def_hidden_ref()
-
-define i32 @main() {
-entry:
-  call void @ext(void ()* bitcast (i32 ()* @hidden_def_weak_def to void ()*))
-  call void @ext(void ()* @protected_def_weak_def)
-  call void @ext(void ()* @protected_def_weak_hidden_def)
-  call void @ext(void ()* @hidden_def_ref)
-  call void @ext(void ()* @hidden_def_weak_ref)
-  call void @ext(void ()* @protected_def_hidden_ref)
-  call void @ext(void ()* @not_imported)
-
-  ;; Calls ensure the functions are imported.
-  call i32 @hidden_def_weak_def()
-  call void @protected_def_weak_def()
-  call void @protected_def_weak_hidden_def()
-  call void @hidden_def_ref()
-  call void @hidden_def_weak_ref()
-  call void @protected_def_hidden_ref()
-  ret i32 0
-}
-
-;--- b.ll
-target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = 

[llvm-branch-commits] [clang] 8bee4d4 - Revert "[LoopDeletion] Allows deletion of possibly infinite side-effect free loops"

2020-12-31 Thread Shaurya Gupta via llvm-branch-commits

Author: Bogdan Graur
Date: 2020-12-31T11:47:49Z
New Revision: 8bee4d4e8f54b5f28b9117b552d3b2c655ff129b

URL: 
https://github.com/llvm/llvm-project/commit/8bee4d4e8f54b5f28b9117b552d3b2c655ff129b
DIFF: 
https://github.com/llvm/llvm-project/commit/8bee4d4e8f54b5f28b9117b552d3b2c655ff129b.diff

LOG: Revert "[LoopDeletion] Allows deletion of possibly infinite side-effect 
free loops"

Test clang/test/Misc/loop-opt-setup.c fails when executed in Release.

This reverts commit 6f1503d59854b331f1f970d39839619b0a26bbc7.

Reviewed By: SureYeaah

Differential Revision: https://reviews.llvm.org/D93956

Added: 


Modified: 
clang/test/Misc/loop-opt-setup.c
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/test/Transforms/LoopDeletion/no-exit-blocks.ll

Removed: 
llvm/test/Transforms/LoopDeletion/mustprogress.ll



diff  --git a/clang/test/Misc/loop-opt-setup.c 
b/clang/test/Misc/loop-opt-setup.c
index 660eea25c6af..c5c2ec4fda84 100644
--- a/clang/test/Misc/loop-opt-setup.c
+++ b/clang/test/Misc/loop-opt-setup.c
@@ -1,5 +1,4 @@
 // RUN: %clang -O1 -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
-// RUN: %clang -std=c99 -O1 -fno-unroll-loops -S -o - %s -emit-llvm | 
FileCheck %s --check-prefix C99
 
 extern int a[16];
 int b = 0;
@@ -25,12 +24,7 @@ void Helper() {
 }
 
 // Check br i1 to make sure the loop is gone, there will still be a label 
branch for the infinite loop.
-// In C99, there was no forward progress requirement, so we expect the 
infinite loop to still exist,
-// but for C11 and onwards, the infinite loop can be deleted.
 // CHECK-LABEL: Helper
-// C99: br label
-// C99-NOT: br i1
-// C99: br label
-// CHECK: entry:
-// CHECK-NOT: br i1
-// CHECK-NEXT: ret void
+// CHECK: br label
+// CHECK-NOT: br i1
+// CHECK: br label

diff  --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h 
b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index fc6b72eb28af..ba2bb0a4c6b0 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -255,9 +255,6 @@ bool hasDisableAllTransformsHint(const Loop *L);
 /// Look for the loop attribute that disables the LICM transformation 
heuristics.
 bool hasDisableLICMTransformsHint(const Loop *L);
 
-/// Look for the loop attribute that requires progress within the loop.
-bool hasMustProgress(const Loop *L);
-
 /// The mode sets how eager a transformation should be applied.
 enum TransformationMode {
   /// The pass can use heuristics to determine whether a transformation should

diff  --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp 
b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index 814cfc7ac6a9..065db647561e 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -128,11 +128,10 @@ static bool isLoopNeverExecuted(Loop *L) {
 
 /// Remove a loop if it is dead.
 ///
-/// A loop is considered dead either if it does not impact the observable
-/// behavior of the program other than finite running time, or if it is
-/// required to make progress by an attribute such as 'mustprogress' or
-/// 'llvm.loop.mustprogress' and does not make any. This may remove
-/// infinite loops that have been required to make progress.
+/// A loop is considered dead if it does not impact the observable behavior of
+/// the program other than finite running time. This never removes a loop that
+/// might be infinite (unless it is never executed), as doing so could change
+/// the halting/non-halting nature of a program.
 ///
 /// This entire process relies pretty heavily on LoopSimplify form and LCSSA in
 /// order to make various safety checks work.
@@ -208,13 +207,11 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, 
DominatorTree &DT,
: LoopDeletionResult::Unmodified;
   }
 
-  // Don't remove loops for which we can't solve the trip count unless the loop
-  // was required to make progress but has been determined to be dead.
+  // Don't remove loops for which we can't solve the trip count.
+  // They could be infinite, in which case we'd be changing program behavior.
   const SCEV *S = SE.getConstantMaxBackedgeTakenCount(L);
-  if (isa(S) &&
-  !L->getHeader()->getParent()->mustProgress() && !hasMustProgress(L)) {
-LLVM_DEBUG(dbgs() << "Could not compute SCEV MaxBackedgeTakenCount and was 
"
- "not required to make progress.\n");
+  if (isa(S)) {
+LLVM_DEBUG(dbgs() << "Could not compute SCEV MaxBackedgeTakenCount.\n");
 return Changed ? LoopDeletionResult::Modified
: LoopDeletionResult::Unmodified;
   }

diff  --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp 
b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 4cd59af6e551..8dc7709c6e55 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llv

[llvm-branch-commits] [llvm] 9b64939 - [NFC] Added tests for PR48604

2020-12-31 Thread Dávid Bolvanský via llvm-branch-commits

Author: Dávid Bolvanský
Date: 2020-12-31T14:03:20+01:00
New Revision: 9b6493946307c321cacc5d1da53bbae5a1acda24

URL: 
https://github.com/llvm/llvm-project/commit/9b6493946307c321cacc5d1da53bbae5a1acda24
DIFF: 
https://github.com/llvm/llvm-project/commit/9b6493946307c321cacc5d1da53bbae5a1acda24.diff

LOG: [NFC] Added tests for PR48604

Added: 


Modified: 
llvm/test/Transforms/InstCombine/and.ll

Removed: 




diff  --git a/llvm/test/Transforms/InstCombine/and.ll 
b/llvm/test/Transforms/InstCombine/and.ll
index 020dbc483d9d..4f054c05889a 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -1217,3 +1217,57 @@ define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) 
{
   %C = and <2 x i8> %B, 
   ret <2 x i8> %C
 }
+
+
+define i32 @and_test(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[O:%.*]] = or i32 [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %o = or i32 %x, %y
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+define i32 @and_test2(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test2(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[O:%.*]] = or i32 [[Y]], [[X]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %o = or i32 %y, %x
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+define i32 @and_test3(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test3(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT:[[O:%.*]] = or i32 [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %y, %x
+  %o = or i32 %x, %y
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+
+define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
+; CHECK-LABEL: @and_vec(
+; CHECK-NEXT:[[A:%.*]] = add <2 x i8> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[O:%.*]] = or <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub <2 x i8> [[A]], [[O]]
+; CHECK-NEXT:ret <2 x i8> [[R]]
+;
+  %a = add <2 x i8> %X, %Y
+  %o = or <2 x i8> %X, %Y
+  %r = sub <2 x i8> %a, %o
+  ret <2 x i8> %r
+}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 742ea77 - [InstCombine] Transform (A + B) - (A | B) to A & B (PR48604)

2020-12-31 Thread Dávid Bolvanský via llvm-branch-commits

Author: Dávid Bolvanský
Date: 2020-12-31T14:03:20+01:00
New Revision: 742ea77ca4c0ea10d8ccd160c7d7f4257d214ed0

URL: 
https://github.com/llvm/llvm-project/commit/742ea77ca4c0ea10d8ccd160c7d7f4257d214ed0
DIFF: 
https://github.com/llvm/llvm-project/commit/742ea77ca4c0ea10d8ccd160c7d7f4257d214ed0.diff

LOG: [InstCombine] Transform (A + B) - (A | B) to A & B (PR48604)

define i32 @src(i32 %x, i32 %y) {
%0:
  %a = add i32 %x, %y
  %o = or i32 %x, %y
  %r = sub i32 %a, %o
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
  %b = and i32 %x, %y
  ret i32 %b
}
Transformation seems to be correct!

https://alive2.llvm.org/ce/z/aQRh2j

Added: 


Modified: 
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/and.ll

Removed: 




diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index c20861f20f07..be145615a241 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1873,6 +1873,14 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator 
&I) {
   return BinaryOperator::CreateXor(A, B);
   }
 
+  // (sub (add A, B) (or A, B)) --> (and A, B)
+  {
+Value *A, *B;
+if (match(Op0, m_Add(m_Value(A), m_Value(B))) &&
+match(Op1, m_c_Or(m_Specific(A), m_Specific(B
+  return BinaryOperator::CreateAnd(A, B);
+  }
+
   // (sub (and A, B) (or A, B)) --> neg (xor A, B)
   {
 Value *A, *B;

diff  --git a/llvm/test/Transforms/InstCombine/and.ll 
b/llvm/test/Transforms/InstCombine/and.ll
index 4f054c05889a..a3d5932ff140 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -1221,9 +1221,7 @@ define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) {
 
 define i32 @and_test(i32 %x, i32 %y) {
 ; CHECK-LABEL: @and_test(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[O:%.*]] = or i32 [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %x, %y
@@ -1234,9 +1232,7 @@ define i32 @and_test(i32 %x, i32 %y) {
 
 define i32 @and_test2(i32 %x, i32 %y) {
 ; CHECK-LABEL: @and_test2(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[O:%.*]] = or i32 [[Y]], [[X]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %x, %y
@@ -1247,9 +1243,7 @@ define i32 @and_test2(i32 %x, i32 %y) {
 
 define i32 @and_test3(i32 %x, i32 %y) {
 ; CHECK-LABEL: @and_test3(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT:[[O:%.*]] = or i32 [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[O]]
+; CHECK-NEXT:[[R:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %y, %x
@@ -1261,9 +1255,7 @@ define i32 @and_test3(i32 %x, i32 %y) {
 
 define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
 ; CHECK-LABEL: @and_vec(
-; CHECK-NEXT:[[A:%.*]] = add <2 x i8> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[O:%.*]] = or <2 x i8> [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub <2 x i8> [[A]], [[O]]
+; CHECK-NEXT:[[R:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret <2 x i8> [[R]]
 ;
   %a = add <2 x i8> %X, %Y



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] c1937c2 - [NFC] Added/adjusted tests for PR48604; second pattern

2020-12-31 Thread Dávid Bolvanský via llvm-branch-commits

Author: Dávid Bolvanský
Date: 2020-12-31T14:59:15+01:00
New Revision: c1937c2af2a03f0b5fda3bbf99e2971ffa04ff0c

URL: 
https://github.com/llvm/llvm-project/commit/c1937c2af2a03f0b5fda3bbf99e2971ffa04ff0c
DIFF: 
https://github.com/llvm/llvm-project/commit/c1937c2af2a03f0b5fda3bbf99e2971ffa04ff0c.diff

LOG: [NFC] Added/adjusted tests for PR48604; second pattern

Added: 


Modified: 
llvm/test/Transforms/InstCombine/and.ll
llvm/test/Transforms/InstCombine/sub.ll

Removed: 




diff  --git a/llvm/test/Transforms/InstCombine/and.ll 
b/llvm/test/Transforms/InstCombine/and.ll
index a3d5932ff140..020dbc483d9d 100644
--- a/llvm/test/Transforms/InstCombine/and.ll
+++ b/llvm/test/Transforms/InstCombine/and.ll
@@ -1217,49 +1217,3 @@ define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) 
{
   %C = and <2 x i8> %B, 
   ret <2 x i8> %C
 }
-
-
-define i32 @and_test(i32 %x, i32 %y) {
-; CHECK-LABEL: @and_test(
-; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:ret i32 [[R]]
-;
-  %a = add i32 %x, %y
-  %o = or i32 %x, %y
-  %r = sub i32 %a, %o
-  ret i32 %r
-}
-
-define i32 @and_test2(i32 %x, i32 %y) {
-; CHECK-LABEL: @and_test2(
-; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:ret i32 [[R]]
-;
-  %a = add i32 %x, %y
-  %o = or i32 %y, %x
-  %r = sub i32 %a, %o
-  ret i32 %r
-}
-
-define i32 @and_test3(i32 %x, i32 %y) {
-; CHECK-LABEL: @and_test3(
-; CHECK-NEXT:[[R:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT:ret i32 [[R]]
-;
-  %a = add i32 %y, %x
-  %o = or i32 %x, %y
-  %r = sub i32 %a, %o
-  ret i32 %r
-}
-
-
-define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
-; CHECK-LABEL: @and_vec(
-; CHECK-NEXT:[[R:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:ret <2 x i8> [[R]]
-;
-  %a = add <2 x i8> %X, %Y
-  %o = or <2 x i8> %X, %Y
-  %r = sub <2 x i8> %a, %o
-  ret <2 x i8> %r
-}

diff  --git a/llvm/test/Transforms/InstCombine/sub.ll 
b/llvm/test/Transforms/InstCombine/sub.ll
index 066085fc2535..aaac3f23f71f 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -1574,3 +1574,99 @@ define i16 @sub_mul_nuw(i16 %x, i16 %y) {
   %r = sub i16 %x8, %y8
   ret i16 %r
 }
+define i32 @and_test(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test(
+; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %o = or i32 %x, %y
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+define i32 @and_test2(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test2(
+; CHECK-NEXT:[[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %o = or i32 %y, %x
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+define i32 @and_test3(i32 %x, i32 %y) {
+; CHECK-LABEL: @and_test3(
+; CHECK-NEXT:[[R:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %y, %x
+  %o = or i32 %x, %y
+  %r = sub i32 %a, %o
+  ret i32 %r
+}
+
+
+define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
+; CHECK-LABEL: @and_vec(
+; CHECK-NEXT:[[R:%.*]] = and <2 x i8> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:ret <2 x i8> [[R]]
+;
+  %a = add <2 x i8> %X, %Y
+  %o = or <2 x i8> %X, %Y
+  %r = sub <2 x i8> %a, %o
+  ret <2 x i8> %r
+}
+
+define i32 @or_test(i32 %x, i32 %y) {
+; CHECK-LABEL: @or_test(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[B:%.*]] = and i32 [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %b = and i32 %x, %y
+  %r = sub i32 %a, %b
+  ret i32 %r
+}
+
+define i32 @or_test2(i32 %x, i32 %y) {
+; CHECK-LABEL: @or_test2(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[B:%.*]] = and i32 [[Y]], [[X]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %x, %y
+  %b = and i32 %y, %x
+  %r = sub i32 %a, %b
+  ret i32 %r
+}
+
+define i32 @or_test3(i32 %x, i32 %y) {
+; CHECK-LABEL: @or_test3(
+; CHECK-NEXT:[[A:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT:[[B:%.*]] = and i32 [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:ret i32 [[R]]
+;
+  %a = add i32 %y, %x
+  %b = and i32 %x, %y
+  %r = sub i32 %a, %b
+  ret i32 %r
+}
+
+define <2 x i8> @or_vec(<2 x i8> %X, <2 x i8> %Y) {
+; CHECK-LABEL: @or_vec(
+; CHECK-NEXT:[[A:%.*]] = add <2 x i8> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:[[B:%.*]] = and <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT:[[R:%.*]] = sub <2 x i8> [[A]], [[B]]
+; CHECK-NEXT:ret <2 x i8> [[R]]
+;
+  %a = add <2 x i8> %X, %Y
+  %b = and <2 x i8> %X, %Y
+  %r = sub <2 x i8> %a, %b
+  ret <2 x i8> %r
+}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commi

[llvm-branch-commits] [llvm] ae69fa9 - [InstCombine] Transform (A + B) - (A & B) to A | B (PR48604)

2020-12-31 Thread Dávid Bolvanský via llvm-branch-commits

Author: Dávid Bolvanský
Date: 2020-12-31T15:04:32+01:00
New Revision: ae69fa9b9f65f59cc0ca8c47f23748a53c8dbdc5

URL: 
https://github.com/llvm/llvm-project/commit/ae69fa9b9f65f59cc0ca8c47f23748a53c8dbdc5
DIFF: 
https://github.com/llvm/llvm-project/commit/ae69fa9b9f65f59cc0ca8c47f23748a53c8dbdc5.diff

LOG: [InstCombine] Transform (A + B) - (A & B) to A | B (PR48604)

define i32 @src(i32 %x, i32 %y) {
%0:
  %a = add i32 %x, %y
  %o = and i32 %x, %y
  %r = sub i32 %a, %o
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
  %b = or i32 %x, %y
  ret i32 %b
}
Transformation seems to be correct!

https://alive2.llvm.org/ce/z/2fhW6r

Added: 


Modified: 
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub.ll

Removed: 




diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index be145615a241..bacb8689892a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1881,6 +1881,14 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator 
&I) {
   return BinaryOperator::CreateAnd(A, B);
   }
 
+  // (sub (add A, B) (and A, B)) --> (or A, B)
+  {
+Value *A, *B;
+if (match(Op0, m_Add(m_Value(A), m_Value(B))) &&
+match(Op1, m_c_And(m_Specific(A), m_Specific(B
+  return BinaryOperator::CreateOr(A, B);
+  }
+
   // (sub (and A, B) (or A, B)) --> neg (xor A, B)
   {
 Value *A, *B;

diff  --git a/llvm/test/Transforms/InstCombine/sub.ll 
b/llvm/test/Transforms/InstCombine/sub.ll
index aaac3f23f71f..649d2e8c2848 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -1621,9 +1621,7 @@ define <2 x i8> @and_vec(<2 x i8> %X, <2 x i8> %Y) {
 
 define i32 @or_test(i32 %x, i32 %y) {
 ; CHECK-LABEL: @or_test(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[B:%.*]] = and i32 [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:[[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %x, %y
@@ -1634,9 +1632,7 @@ define i32 @or_test(i32 %x, i32 %y) {
 
 define i32 @or_test2(i32 %x, i32 %y) {
 ; CHECK-LABEL: @or_test2(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[B:%.*]] = and i32 [[Y]], [[X]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:[[R:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %x, %y
@@ -1647,9 +1643,7 @@ define i32 @or_test2(i32 %x, i32 %y) {
 
 define i32 @or_test3(i32 %x, i32 %y) {
 ; CHECK-LABEL: @or_test3(
-; CHECK-NEXT:[[A:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT:[[B:%.*]] = and i32 [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub i32 [[A]], [[B]]
+; CHECK-NEXT:[[R:%.*]] = or i32 [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %a = add i32 %y, %x
@@ -1660,9 +1654,7 @@ define i32 @or_test3(i32 %x, i32 %y) {
 
 define <2 x i8> @or_vec(<2 x i8> %X, <2 x i8> %Y) {
 ; CHECK-LABEL: @or_vec(
-; CHECK-NEXT:[[A:%.*]] = add <2 x i8> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:[[B:%.*]] = and <2 x i8> [[X]], [[Y]]
-; CHECK-NEXT:[[R:%.*]] = sub <2 x i8> [[A]], [[B]]
+; CHECK-NEXT:[[R:%.*]] = or <2 x i8> [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:ret <2 x i8> [[R]]
 ;
   %a = add <2 x i8> %X, %Y



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] d7154bb - [ThinLTO][test] Add visibility related tests

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T09:16:35-08:00
New Revision: d7154bbf92b3606220a11834a62ab7e9cd17be42

URL: 
https://github.com/llvm/llvm-project/commit/d7154bbf92b3606220a11834a62ab7e9cd17be42
DIFF: 
https://github.com/llvm/llvm-project/commit/d7154bbf92b3606220a11834a62ab7e9cd17be42.diff

LOG: [ThinLTO][test] Add visibility related tests

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D92899

Added: 
llvm/test/ThinLTO/X86/visibility-elf.ll
llvm/test/ThinLTO/X86/visibility-macho.ll

Modified: 


Removed: 




diff  --git a/llvm/test/ThinLTO/X86/visibility-elf.ll 
b/llvm/test/ThinLTO/X86/visibility-elf.ll
new file mode 100644
index ..8b2e36afcac6
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/visibility-elf.ll
@@ -0,0 +1,137 @@
+; RUN: split-file %s %t
+; RUN: opt -module-summary %t/a.ll -o %ta.bc
+; RUN: opt -module-summary %t/b.ll -o %tb.bc
+
+;; Test visibility propagation. The prevailing definitions are all from %tb.bc.
+; RUN: llvm-lto2 run -save-temps -o %t1.bc %ta.bc %tb.bc \
+; RUN:   -r=%ta.bc,var1,l -r=%ta.bc,var2,l \
+; RUN:   -r=%ta.bc,hidden_def_weak_def,l -r=%ta.bc,protected_def_weak_def,l 
-r=%ta.bc,protected_def_weak_hidden_def,l \
+; RUN:   -r=%ta.bc,protected_def_hidden_ref,l -r=%ta.bc,not_imported,l 
-r=%ta.bc,hidden_def_ref,l \
+; RUN:   -r=%ta.bc,hidden_def_weak_ref,l \
+; RUN:   -r=%ta.bc,ext, -r=%ta.bc,main,plx \
+; RUN:   -r=%tb.bc,var1,plx -r=%tb.bc,var2,plx \
+; RUN:   -r=%tb.bc,hidden_def_weak_def,pl -r=%tb.bc,protected_def_weak_def,pl 
-r=%tb.bc,protected_def_weak_hidden_def,pl \
+; RUN:   -r=%tb.bc,protected_def_hidden_ref,pl -r=%tb.bc,not_imported,pl 
-r=%tb.bc,hidden_def_ref,pl \
+; RUN:   -r=%tb.bc,hidden_def_weak_ref,pl
+; RUN: llvm-dis < %t1.bc.1.3.import.bc | FileCheck %s
+
+;; %tb.bc does not import anything, so we just check 1.promote.
+; RUN: llvm-dis < %t1.bc.2.1.promote.bc | FileCheck %s --check-prefix=CHECK2
+
+;--- a.ll
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK:  @var1 = external global i32, align 4
+; CHECK-NEXT: @var2 = available_externally hidden global i32 1, align 4
+
+@var1 = weak global i32 1, align 4
+@var2 = extern_weak global i32
+
+declare void @ext(void ()*)
+
+; CHECK: declare i32 @hidden_def_weak_def()
+; CHECK: declare void @protected_def_weak_def()
+; CHECK: declare hidden void @protected_def_weak_hidden_def()
+;; Currently the visibility is not propagated onto an unimported function,
+;; because we don't have summaries for declarations.
+; CHECK: declare extern_weak void @not_imported()
+; CHECK: define available_externally hidden void @hidden_def_ref() 
!thinlto_src_module !0
+; CHECK: define available_externally hidden void @hidden_def_weak_ref() 
!thinlto_src_module !0
+;; This can be hidden, but we cannot communicate the declaration's visibility
+;; to other modules because declarations don't have summaries, and the IRLinker
+;; overrides it when importing the protected def.
+; CHECK: define available_externally protected void 
@protected_def_hidden_ref() !thinlto_src_module !0
+
+; CHECK2: define hidden i32 @hidden_def_weak_def()
+; CHECK2: define protected void @protected_def_weak_def()
+; CHECK2: define protected void @protected_def_weak_hidden_def()
+; CHECK2: define hidden void @hidden_def_ref()
+; CHECK2: define hidden void @hidden_def_weak_ref()
+; CHECK2: define protected void @protected_def_hidden_ref()
+; CHECK2: define hidden void @not_imported()
+
+define weak i32 @hidden_def_weak_def() {
+entry:
+  %0 = load i32, i32* @var2
+  ret i32 %0
+}
+
+define weak void @protected_def_weak_def() {
+entry:
+  ret void
+}
+
+define weak hidden void @protected_def_weak_hidden_def() {
+entry:
+  ret void
+}
+
+declare extern_weak void @not_imported()
+
+declare void @hidden_def_ref()
+declare extern_weak void @hidden_def_weak_ref()
+declare hidden void @protected_def_hidden_ref()
+
+define i32 @main() {
+entry:
+  call void @ext(void ()* bitcast (i32 ()* @hidden_def_weak_def to void ()*))
+  call void @ext(void ()* @protected_def_weak_def)
+  call void @ext(void ()* @protected_def_weak_hidden_def)
+  call void @ext(void ()* @hidden_def_ref)
+  call void @ext(void ()* @hidden_def_weak_ref)
+  call void @ext(void ()* @protected_def_hidden_ref)
+  call void @ext(void ()* @not_imported)
+
+  ;; Calls ensure the functions are imported.
+  call i32 @hidden_def_weak_def()
+  call void @protected_def_weak_def()
+  call void @protected_def_weak_hidden_def()
+  call void @hidden_def_ref()
+  call void @hidden_def_weak_ref()
+  call void @protected_def_hidden_ref()
+  ret i32 0
+}
+
+;--- b.ll
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@var1 = hidden global i32 1, align 4
+@var2 = hidden global i32 1, align 4
+
+defi

[llvm-branch-commits] [llvm] 728f99f - [ThinLTO][test] Specify -enable-import-metadata to make !thinlto_src_module available in -DLLVM_ENABLE_ASSERTIONS=off mode

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T09:31:53-08:00
New Revision: 728f99fa0b6c13ce7d4608e5ba6e0d0bfbdaddbb

URL: 
https://github.com/llvm/llvm-project/commit/728f99fa0b6c13ce7d4608e5ba6e0d0bfbdaddbb
DIFF: 
https://github.com/llvm/llvm-project/commit/728f99fa0b6c13ce7d4608e5ba6e0d0bfbdaddbb.diff

LOG: [ThinLTO][test] Specify -enable-import-metadata to make 
!thinlto_src_module available in -DLLVM_ENABLE_ASSERTIONS=off mode

Added: 


Modified: 
llvm/test/ThinLTO/X86/visibility-elf.ll
llvm/test/ThinLTO/X86/visibility-macho.ll

Removed: 




diff  --git a/llvm/test/ThinLTO/X86/visibility-elf.ll 
b/llvm/test/ThinLTO/X86/visibility-elf.ll
index 8b2e36afcac6..74e2e7ca9bb6 100644
--- a/llvm/test/ThinLTO/X86/visibility-elf.ll
+++ b/llvm/test/ThinLTO/X86/visibility-elf.ll
@@ -3,7 +3,7 @@
 ; RUN: opt -module-summary %t/b.ll -o %tb.bc
 
 ;; Test visibility propagation. The prevailing definitions are all from %tb.bc.
-; RUN: llvm-lto2 run -save-temps -o %t1.bc %ta.bc %tb.bc \
+; RUN: llvm-lto2 run -save-temps -enable-import-metadata -o %t1.bc %ta.bc 
%tb.bc \
 ; RUN:   -r=%ta.bc,var1,l -r=%ta.bc,var2,l \
 ; RUN:   -r=%ta.bc,hidden_def_weak_def,l -r=%ta.bc,protected_def_weak_def,l 
-r=%ta.bc,protected_def_weak_hidden_def,l \
 ; RUN:   -r=%ta.bc,protected_def_hidden_ref,l -r=%ta.bc,not_imported,l 
-r=%ta.bc,hidden_def_ref,l \

diff  --git a/llvm/test/ThinLTO/X86/visibility-macho.ll 
b/llvm/test/ThinLTO/X86/visibility-macho.ll
index 72fee600c80e..6e62cc0649ff 100644
--- a/llvm/test/ThinLTO/X86/visibility-macho.ll
+++ b/llvm/test/ThinLTO/X86/visibility-macho.ll
@@ -3,7 +3,7 @@
 ; RUN: opt -module-summary %t/b.ll -o %tb.bc
 
 ;; Test visibility propagation. The prevailing definitions are all from %tb.bc.
-; RUN: llvm-lto2 run -save-temps -o %t1.bc %ta.bc %tb.bc \
+; RUN: llvm-lto2 run -save-temps -enable-import-metadata -o %t1.bc %ta.bc 
%tb.bc \
 ; RUN:   -r=%ta.bc,_var1,l -r=%ta.bc,_var2,l \
 ; RUN:   -r=%ta.bc,_hidden_def_weak_def,l -r=%ta.bc,_not_imported,l 
-r=%ta.bc,_hidden_def_ref,l \
 ; RUN:   -r=%ta.bc,_hidden_def_weak_ref,l \



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] f904b46 - [llvm-objcopy] Use llvm::erase_if (NFC)

2020-12-31 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2020-12-31T09:39:09-08:00
New Revision: f904b46b1a965013a51854fafbb63763617e33b3

URL: 
https://github.com/llvm/llvm-project/commit/f904b46b1a965013a51854fafbb63763617e33b3
DIFF: 
https://github.com/llvm/llvm-project/commit/f904b46b1a965013a51854fafbb63763617e33b3.diff

LOG: [llvm-objcopy] Use llvm::erase_if (NFC)

Added: 


Modified: 
llvm/tools/llvm-objcopy/COFF/Object.cpp

Removed: 




diff  --git a/llvm/tools/llvm-objcopy/COFF/Object.cpp 
b/llvm/tools/llvm-objcopy/COFF/Object.cpp
index cf3afe5e545e..a706000c0df4 100644
--- a/llvm/tools/llvm-objcopy/COFF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/Object.cpp
@@ -99,31 +99,24 @@ void Object::removeSections(function_ref ToRemove) {
   };
   do {
 DenseSet RemovedSections;
-Sections.erase(
-std::remove_if(std::begin(Sections), std::end(Sections),
-   [ToRemove, &RemovedSections](const Section &Sec) {
- bool Remove = ToRemove(Sec);
- if (Remove)
-   RemovedSections.insert(Sec.UniqueId);
- return Remove;
-   }),
-std::end(Sections));
+llvm::erase_if(Sections, [ToRemove, &RemovedSections](const Section &Sec) {
+  bool Remove = ToRemove(Sec);
+  if (Remove)
+RemovedSections.insert(Sec.UniqueId);
+  return Remove;
+});
 // Remove all symbols referring to the removed sections.
 AssociatedSections.clear();
-Symbols.erase(
-std::remove_if(
-std::begin(Symbols), std::end(Symbols),
-[&RemovedSections, &AssociatedSections](const Symbol &Sym) {
-  // If there are sections that are associative to a removed
-  // section,
-  // remove those as well as nothing will include them (and we 
can't
-  // leave them dangling).
-  if (RemovedSections.count(Sym.AssociativeComdatTargetSectionId) 
==
-  1)
-AssociatedSections.insert(Sym.TargetSectionId);
-  return RemovedSections.count(Sym.TargetSectionId) == 1;
-}),
-std::end(Symbols));
+llvm::erase_if(
+Symbols, [&RemovedSections, &AssociatedSections](const Symbol &Sym) {
+  // If there are sections that are associative to a removed
+  // section,
+  // remove those as well as nothing will include them (and we can't
+  // leave them dangling).
+  if (RemovedSections.count(Sym.AssociativeComdatTargetSectionId) == 1)
+AssociatedSections.insert(Sym.TargetSectionId);
+  return RemovedSections.count(Sym.TargetSectionId) == 1;
+});
 ToRemove = RemoveAssociated;
   } while (!AssociatedSections.empty());
   updateSections();



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 7bc76fd - [CodeGen] Construct SmallVector with iterator ranges (NFC)

2020-12-31 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2020-12-31T09:39:11-08:00
New Revision: 7bc76fd0ec40ae20b6d456e2d6e7c328615ed718

URL: 
https://github.com/llvm/llvm-project/commit/7bc76fd0ec40ae20b6d456e2d6e7c328615ed718
DIFF: 
https://github.com/llvm/llvm-project/commit/7bc76fd0ec40ae20b6d456e2d6e7c328615ed718.diff

LOG: [CodeGen] Construct SmallVector with iterator ranges (NFC)

Added: 


Modified: 
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/IfConversion.cpp
llvm/lib/CodeGen/MachineBlockPlacement.cpp
llvm/lib/CodeGen/MachineSink.cpp
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
llvm/lib/CodeGen/ReachingDefAnalysis.cpp
llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
llvm/lib/CodeGen/SjLjEHPrepare.cpp
llvm/lib/CodeGen/TailDuplicator.cpp
llvm/lib/CodeGen/WasmEHPrepare.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 3ea758a48bad..4a82c9570cc2 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -562,7 +562,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
 // are removed.
 SmallSetVector WorkList;
 for (BasicBlock &BB : F) {
-  SmallVector Successors(succ_begin(&BB), succ_end(&BB));
+  SmallVector Successors(successors(&BB));
   MadeChange |= ConstantFoldTerminator(&BB, true);
   if (!MadeChange) continue;
 
@@ -576,7 +576,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
 MadeChange |= !WorkList.empty();
 while (!WorkList.empty()) {
   BasicBlock *BB = WorkList.pop_back_val();
-  SmallVector Successors(succ_begin(BB), succ_end(BB));
+  SmallVector Successors(successors(BB));
 
   DeleteDeadBlock(BB);
 
@@ -5328,7 +5328,7 @@ bool 
CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
 if (MemoryInst->getParent() != GEP->getParent())
   return false;
 
-SmallVector Ops(GEP->op_begin(), GEP->op_end());
+SmallVector Ops(GEP->operands());
 
 bool RewriteGEP = false;
 

diff  --git a/llvm/lib/CodeGen/IfConversion.cpp 
b/llvm/lib/CodeGen/IfConversion.cpp
index d149f8c3a139..37be2eabf5fe 100644
--- a/llvm/lib/CodeGen/IfConversion.cpp
+++ b/llvm/lib/CodeGen/IfConversion.cpp
@@ -2264,8 +2264,7 @@ void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo 
&FromBBI, bool AddEdges) {
   if (ToBBI.IsBrAnalyzable)
 ToBBI.BB->normalizeSuccProbs();
 
-  SmallVector FromSuccs(FromMBB.succ_begin(),
-FromMBB.succ_end());
+  SmallVector FromSuccs(FromMBB.successors());
   MachineBasicBlock *NBB = getNextBlock(FromMBB);
   MachineBasicBlock *FallThrough = FromBBI.HasFallThrough ? NBB : nullptr;
   // The edge probability from ToBBI.BB to FromMBB, which is only needed when

diff  --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp 
b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 8850dab30fa5..048baa460e49 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3160,8 +3160,8 @@ void MachineBlockPlacement::findDuplicateCandidates(
   MachineBasicBlock *Fallthrough = nullptr;
   BranchProbability DefaultBranchProb = BranchProbability::getZero();
   BlockFrequency BBDupThreshold(scaleThreshold(BB));
-  SmallVector Preds(BB->pred_begin(), BB->pred_end());
-  SmallVector Succs(BB->succ_begin(), BB->succ_end());
+  SmallVector Preds(BB->predecessors());
+  SmallVector Succs(BB->successors());
 
   // Sort for highest frequency.
   auto CmpSucc = [&](MachineBasicBlock *A, MachineBasicBlock *B) {

diff  --git a/llvm/lib/CodeGen/MachineSink.cpp 
b/llvm/lib/CodeGen/MachineSink.cpp
index 265ca6dcb894..48ed8b0c5e73 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -745,8 +745,7 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, 
MachineBasicBlock *MBB,
   if (Succs != AllSuccessors.end())
 return Succs->second;
 
-  SmallVector AllSuccs(MBB->succ_begin(),
-   MBB->succ_end());
+  SmallVector AllSuccs(MBB->successors());
 
   // Handle cases where sinking can happen but where the sink point isn't a
   // successor. For example:

diff  --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp 
b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 1be9544848ec..80c38f3ec341 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -96,7 +96,7 @@ static bool lowerObjCCall(Function &F, const char *NewFn,
 ++I;
 
 IRBuilder<> Builder(CI->getParent(), CI->getIterator());
-SmallVector Args(CI->arg_begin(), CI->arg_end());
+SmallVector Args(CI->args());
 CallInst *NewCI = Builder.CreateCall(FCache, Args);
 NewCI->setName(CI->getName());
 

diff  --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp 
b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index 2f0a622d3846..d16e90a7e

[llvm-branch-commits] [llvm] b557c32 - [MemorySSA, BPF] Use isa instead of dyn_cast (NFC)

2020-12-31 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2020-12-31T09:39:13-08:00
New Revision: b557c32ae925e0aa39d40e0254380953aad1c78f

URL: 
https://github.com/llvm/llvm-project/commit/b557c32ae925e0aa39d40e0254380953aad1c78f
DIFF: 
https://github.com/llvm/llvm-project/commit/b557c32ae925e0aa39d40e0254380953aad1c78f.diff

LOG: [MemorySSA, BPF] Use isa instead of dyn_cast (NFC)

Added: 


Modified: 
llvm/lib/Analysis/MemorySSA.cpp
llvm/lib/Target/BPF/BPFAdjustOpt.cpp

Removed: 




diff  --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp
index c9ad9ffab16e..e728a5f998f4 100644
--- a/llvm/lib/Analysis/MemorySSA.cpp
+++ b/llvm/lib/Analysis/MemorySSA.cpp
@@ -1779,8 +1779,8 @@ MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I,
 
   bool Def, Use;
   if (Template) {
-Def = dyn_cast_or_null(Template) != nullptr;
-Use = dyn_cast_or_null(Template) != nullptr;
+Def = isa(Template);
+Use = isa(Template);
 #if !defined(NDEBUG)
 ModRefInfo ModRef = AAP->getModRefInfo(I, None);
 bool DefCheck, UseCheck;

diff  --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp 
b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
index 6afd2d77485d..928b591b2274 100644
--- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -221,7 +221,7 @@ bool BPFAdjustOptImpl::avoidSpeculation(Instruction &I) {
 }
   }
 
-  if (!dyn_cast(&I) && !dyn_cast(&I))
+  if (!isa(&I) && !isa(&I))
 return false;
 
   // For:



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] a90b42b - [ThinLTO] Default -enable-import-metadata to false

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T10:04:21-08:00
New Revision: a90b42b0fec618124a3ed573ecd0e192a61815f7

URL: 
https://github.com/llvm/llvm-project/commit/a90b42b0fec618124a3ed573ecd0e192a61815f7
DIFF: 
https://github.com/llvm/llvm-project/commit/a90b42b0fec618124a3ed573ecd0e192a61815f7.diff

LOG: [ThinLTO] Default -enable-import-metadata to false

The default value is dependent on `-DLLVM_ENABLE_ASSERTIONS={off,on}` (D22167), 
which is
error-prone. The few tests checking `!thinlto_src_module` can specify 
-enable-import-metadata explicitly.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D93959

Added: 


Modified: 
llvm/lib/Transforms/IPO/FunctionImport.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp 
b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 3015a5f8ee37..18343030bc6a 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -124,14 +124,8 @@ static cl::opt ComputeDead("compute-dead", 
cl::init(true), cl::Hidden,
  cl::desc("Compute dead symbols"));
 
 static cl::opt EnableImportMetadata(
-"enable-import-metadata", cl::init(
-#if !defined(NDEBUG)
-  true /*Enabled with asserts.*/
-#else
-  false
-#endif
-  ),
-cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'"));
+"enable-import-metadata", cl::init(false), cl::Hidden,
+cl::desc("Enable import metadata like 'thinlto_src_module'"));
 
 /// Summary file to use for function importing when using -function-import from
 /// the command line.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 1a9eb19 - [IROutliner] Adding consistent function attribute merging

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T12:30:23-06:00
New Revision: 1a9eb19af9ba1c6fcd63f84f4053c77881e6ae1c

URL: 
https://github.com/llvm/llvm-project/commit/1a9eb19af9ba1c6fcd63f84f4053c77881e6ae1c
DIFF: 
https://github.com/llvm/llvm-project/commit/1a9eb19af9ba1c6fcd63f84f4053c77881e6ae1c.diff

LOG: [IROutliner] Adding consistent function attribute merging

When combining extracted functions, they may have different function
attributes. We want to make sure that we do not make any assumptions,
or lose any information. This attempts to make sure that we consolidate
function attributes to their most general case.

Tests:
llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll
llvm/test/Transforms/IROutliner/outlining-compatible-or-attribute-transfer.ll

Reviewers: jdoefert, paquette

Differential Revision: https://reviews.llvm.org/D87301

Added: 

llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll

llvm/test/Transforms/IROutliner/outlining-compatible-or-attribute-transfer.ll

Modified: 
llvm/include/llvm/IR/Attributes.h
llvm/lib/IR/Attributes.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp

Removed: 




diff  --git a/llvm/include/llvm/IR/Attributes.h 
b/llvm/include/llvm/IR/Attributes.h
index bf9595962bd0..fbfe5854594f 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -951,9 +951,24 @@ AttrBuilder typeIncompatible(Type *Ty);
 /// attributes for inlining purposes.
 bool areInlineCompatible(const Function &Caller, const Function &Callee);
 
+
+/// Checks  if there are any incompatible function attributes between
+/// \p A and \p B.
+///
+/// \param [in] A - The first function to be compared with.
+/// \param [in] B - The second function to be compared with.
+/// \returns true if the functions have compatible attributes.
+bool areOutlineCompatible(const Function &A, const Function &B);
+
 /// Merge caller's and callee's attributes.
 void mergeAttributesForInlining(Function &Caller, const Function &Callee);
 
+/// Merges the functions attributes from \p ToMerge into function \p Base.
+///
+/// \param [in,out] Base - The function being merged into.
+/// \param [in] ToMerge - The function to merge attributes from.
+void mergeAttributesForOutlining(Function &Base, const Function &ToMerge);
+
 } // end namespace AttributeFuncs
 
 } // end namespace llvm

diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 7001ab82331d..d39cdf7db04e 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2091,7 +2091,25 @@ bool AttributeFuncs::areInlineCompatible(const Function 
&Caller,
   return hasCompatibleFnAttrs(Caller, Callee);
 }
 
+bool AttributeFuncs::areOutlineCompatible(const Function &A,
+  const Function &B) {
+  return hasCompatibleFnAttrs(A, B);
+}
+
 void AttributeFuncs::mergeAttributesForInlining(Function &Caller,
 const Function &Callee) {
   mergeFnAttrs(Caller, Callee);
 }
+
+void AttributeFuncs::mergeAttributesForOutlining(Function &Base,
+const Function &ToMerge) {
+
+  // We merge functions so that they meet the most general case.
+  // For example, if the NoNansFPMathAttr is set in one function, but not in
+  // the other, in the merged function we can say that the NoNansFPMathAttr
+  // is not set.
+  // However if we have the SpeculativeLoadHardeningAttr set true in one
+  // function, but not the other, we make sure that the function retains
+  // that aspect in the merged function.
+  mergeFnAttrs(Base, ToMerge);
+}

diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp 
b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 908ba0c70e70..01605769bcff 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1201,6 +1201,8 @@ void IROutliner::deduplicateExtractedSections(
 
   for (unsigned Idx = 1; Idx < CurrentGroup.Regions.size(); Idx++) {
 CurrentOS = CurrentGroup.Regions[Idx];
+AttributeFuncs::mergeAttributesForOutlining(*CurrentGroup.OutlinedFunction,
+   *CurrentOS->ExtractedFunction);
 
 // Create a new BasicBlock to hold the needed store instructions.
 BasicBlock *NewBB = BasicBlock::Create(

diff  --git 
a/llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll
 
b/llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll
new file mode 100644
index ..0a051883b069
--- /dev/null
+++ 
b/llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll
@@ -0,0 +1,126 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -verify -iroutliner < %s | FileCheck %s
+
+; This has two compatible regions based on function attributes.  We h

[llvm-branch-commits] [clang] 1a65b8c - [Clang][Misc] Change run line in fragile test

2020-12-31 Thread via llvm-branch-commits

Author: Atmn
Date: 2020-12-31T13:48:21-05:00
New Revision: 1a65b8c739a09c587fb55ef4d2d7def13718111c

URL: 
https://github.com/llvm/llvm-project/commit/1a65b8c739a09c587fb55ef4d2d7def13718111c
DIFF: 
https://github.com/llvm/llvm-project/commit/1a65b8c739a09c587fb55ef4d2d7def13718111c.diff

LOG: [Clang][Misc] Change run line in fragile test

This test has %clang in the run line when it should have %clang_cc1.
This should prevent future release test failures.

Differential Revision: https://reviews.llvm.org/D93952

Added: 


Modified: 
clang/test/Misc/loop-opt-setup.c

Removed: 




diff  --git a/clang/test/Misc/loop-opt-setup.c 
b/clang/test/Misc/loop-opt-setup.c
index c5c2ec4fda84..9cea02a8bcb3 100644
--- a/clang/test/Misc/loop-opt-setup.c
+++ b/clang/test/Misc/loop-opt-setup.c
@@ -1,4 +1,5 @@
-// RUN: %clang -O1 -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
+// This relies on %clang_cc1, %clang does not emit the block names in Release 
mode.
+// RUN: %clang_cc1 -O1 -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
 
 extern int a[16];
 int b = 0;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 509fa8e - [SCEV] recognize logical and/or pattern

2020-12-31 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-01T04:37:57+09:00
New Revision: 509fa8e02e25a610574c0fc2cceea1d350c35a66

URL: 
https://github.com/llvm/llvm-project/commit/509fa8e02e25a610574c0fc2cceea1d350c35a66
DIFF: 
https://github.com/llvm/llvm-project/commit/509fa8e02e25a610574c0fc2cceea1d350c35a66.diff

LOG: [SCEV] recognize logical and/or pattern

This patch makes SCEV recognize 'select A, B, false' and 'select A, true, B'.
This is a performance improvement that will be helpful after unsound select -> 
and/or transformation is removed, as discussed in D93065.

SCEV's answers for the select form should be a bit more conservative than the 
equivalent `and A, B` / `or A, B`.
Take this example: https://alive2.llvm.org/ce/z/NsP9ue .
To check whether it is valid for SCEV's computeExitLimit to return min(n, m) as 
ExactNotTaken value, I put llvm.assume at tgt.
It fails because the exit limit becomes poison if n is zero and m is poison. 
This is problematic if e.g. the exit value of i is replaced with min(n, m).
If either n or m is constant, we can revive the analysis again. I added 
relevant tests and put alive2 links there.

If and is used instead, this is okay: https://alive2.llvm.org/ce/z/K9rbJk . 
Hence the existing analysis is sound.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D93882

Added: 
llvm/test/Analysis/ScalarEvolution/exit-count-select.ll
llvm/test/Analysis/ScalarEvolution/trip-count-andor-selectform.ll

Modified: 
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 




diff  --git a/llvm/include/llvm/Analysis/ScalarEvolution.h 
b/llvm/include/llvm/Analysis/ScalarEvolution.h
index a7a24f086fbe..b3f199de2cfa 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1676,10 +1676,7 @@ class ScalarEvolution {
   computeExitLimitFromCondFromBinOp(ExitLimitCacheTy &Cache, const Loop *L,
 Value *ExitCond, bool ExitIfTrue,
 bool ControlsExit, bool AllowPredicates);
-  ExitLimit computeExitLimitFromCondFromBinOpHelper(
-  ExitLimitCacheTy &Cache, const Loop *L, BinaryOperator *BO,
-  bool EitherMayExit, bool ExitIfTrue, bool ControlsExit,
-  bool AllowPredicates, const Constant *NeutralElement);
+
   /// Compute the number of times the backedge of the specified loop will
   /// execute if its exit condition were a conditional branch of the ICmpInst
   /// ExitCond and ExitIfTrue. If AllowPredicates is set, this call will try

diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index b0ead7349ba5..3c284007cc2d 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -135,6 +135,7 @@
 #include 
 
 using namespace llvm;
+using namespace PatternMatch;
 
 #define DEBUG_TYPE "scalar-evolution"
 
@@ -7578,47 +7579,64 @@ ScalarEvolution::computeExitLimitFromCondFromBinOp(
 ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond, bool ExitIfTrue,
 bool ControlsExit, bool AllowPredicates) {
   // Check if the controlling expression for this loop is an And or Or.
-  if (auto *BO = dyn_cast(ExitCond)) {
-if (BO->getOpcode() == Instruction::And)
-  return computeExitLimitFromCondFromBinOpHelper(
-  Cache, L, BO, !ExitIfTrue, ExitIfTrue, ControlsExit, AllowPredicates,
-  ConstantInt::get(BO->getType(), 1));
-if (BO->getOpcode() == Instruction::Or)
-  return computeExitLimitFromCondFromBinOpHelper(
-  Cache, L, BO, ExitIfTrue, ExitIfTrue, ControlsExit, AllowPredicates,
-  ConstantInt::get(BO->getType(), 0));
-  }
-  return None;
-}
+  Value *Op0, *Op1;
+  bool IsAnd = false;
+  if (match(ExitCond, m_LogicalAnd(m_Value(Op0), m_Value(Op1
+IsAnd = true;
+  else if (match(ExitCond, m_LogicalOr(m_Value(Op0), m_Value(Op1
+IsAnd = false;
+  else
+return None;
+
+  // EitherMayExit is true in these two cases:
+  //   br (and Op0 Op1), loop, exit
+  //   br (or  Op0 Op1), exit, loop
+  bool EitherMayExit = IsAnd ^ ExitIfTrue;
+  ExitLimit EL0 = computeExitLimitFromCondCached(Cache, L, Op0, ExitIfTrue,
+ ControlsExit && 
!EitherMayExit,
+ AllowPredicates);
+  ExitLimit EL1 = computeExitLimitFromCondCached(Cache, L, Op1, ExitIfTrue,
+ ControlsExit && 
!EitherMayExit,
+ AllowPredicates);
+
+  // Be robust against unsimplified IR for the form "op i1 X, NeutralElement"
+  const Constant *NeutralElement = ConstantInt::get(ExitCond->getType(), 
IsAnd);
+  if (isa(Op1))
+return Op1 == NeutralElement ? EL0 : EL1;
+  if (isa(Op0))
+return Op0 == NeutralElement ? EL1 : EL0;
 
-ScalarEvolution::

[llvm-branch-commits] [llvm] 5cdf6ed - [CodeGen] recognize select form of and/ors when splitting branch conditions

2020-12-31 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-01T04:46:10+09:00
New Revision: 5cdf6ed744896a23ebc3f723ee2abcfc88137da0

URL: 
https://github.com/llvm/llvm-project/commit/5cdf6ed744896a23ebc3f723ee2abcfc88137da0
DIFF: 
https://github.com/llvm/llvm-project/commit/5cdf6ed744896a23ebc3f723ee2abcfc88137da0.diff

LOG: [CodeGen] recognize select form of and/ors when splitting branch conditions

Recently a few patches are made to move towards using select i1 instead of 
and/or i1 to represent "a && b"/"a || b" in C/C++.
"a && b" in C/C++ does not evaluate b if a is false whereas 'and a, b' in IR 
evaluates b and uses its result regardless of the result of a.
This is problematic because it can cause miscompilation if b was an erroneous 
operation (https://llvm.org/pr48353).
In C/C++, the result is simply false because b is not evaluated, but in IR the 
result is poison.
The discussion at D93065 has more context about this.

This patch makes two branch-splitting optimizations (one in 
SelectionDAGBuilder, one in CodeGenPrepare) recognize
select form of and/or as well using m_LogicalAnd/Or.
Since it is CodeGen, I think this is semantically ok (at least as safe as what 
codegen already did).

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D93853

Added: 


Modified: 
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-condbr-lower-tree.ll
llvm/test/CodeGen/AArch64/arm64_32.ll
llvm/test/CodeGen/AArch64/fast-isel-branch-cond-split.ll

Removed: 




diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 4a82c9570cc2..d64a8f26519f 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -7838,9 +7838,10 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, 
bool &ModifiedDT) {
 //   %cond2 = icmp|fcmp|binary instruction ...
 //   %cond.or = or|and i1 %cond1, cond2
 //   br i1 %cond.or label %dest1, label %dest2"
-BinaryOperator *LogicOp;
+Instruction *LogicOp;
 BasicBlock *TBB, *FBB;
-if (!match(BB.getTerminator(), m_Br(m_OneUse(m_BinOp(LogicOp)), TBB, FBB)))
+if (!match(BB.getTerminator(),
+   m_Br(m_OneUse(m_Instruction(LogicOp)), TBB, FBB)))
   continue;
 
 auto *Br1 = cast(BB.getTerminator());
@@ -7853,17 +7854,22 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, 
bool &ModifiedDT) {
 
 unsigned Opc;
 Value *Cond1, *Cond2;
-if (match(LogicOp, m_And(m_OneUse(m_Value(Cond1)),
- m_OneUse(m_Value(Cond2)
+if (match(LogicOp,
+  m_LogicalAnd(m_OneUse(m_Value(Cond1)), 
m_OneUse(m_Value(Cond2)
   Opc = Instruction::And;
-else if (match(LogicOp, m_Or(m_OneUse(m_Value(Cond1)),
- m_OneUse(m_Value(Cond2)
+else if (match(LogicOp, m_LogicalOr(m_OneUse(m_Value(Cond1)),
+m_OneUse(m_Value(Cond2)
   Opc = Instruction::Or;
 else
   continue;
 
-if (!match(Cond1, m_CombineOr(m_Cmp(), m_BinOp())) ||
-!match(Cond2, m_CombineOr(m_Cmp(), m_BinOp()))   )
+auto IsGoodCond = [](Value *Cond) {
+  return match(
+  Cond,
+  m_CombineOr(m_Cmp(), m_CombineOr(m_LogicalAnd(m_Value(), m_Value()),
+   m_LogicalOr(m_Value(), 
m_Value();
+};
+if (!IsGoodCond(Cond1) || !IsGoodCond(Cond2))
   continue;
 
 LLVM_DEBUG(dbgs() << "Before branch condition splitting\n"; BB.dump());

diff  --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp 
b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index dde97ba599b9..c80821746c14 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -426,14 +426,19 @@ void IRTranslator::findMergedConditions(
   }
 
   const Instruction *BOp = dyn_cast(Cond);
+  const Value *BOpOp0, *BOpOp1;
   // Compute the effective opcode for Cond, taking into account whether it 
needs
   // to be inverted, e.g.
   //   and (not (or A, B)), C
   // gets lowered as
   //   and (and (not A, not B), C)
-  unsigned BOpc = 0;
+  Instruction::BinaryOps BOpc = (Instruction::BinaryOps)0;
   if (BOp) {
-BOpc = BOp->getOpcode();
+BOpc = match(BOp, m_LogicalAnd(m_Value(BOpOp0), m_Value(BOpOp1)))
+   ? Instruction::And
+   : (match(BOp, m_LogicalOr(m_Value(BOpOp0), m_Value(BOpOp1)))
+  ? Instruction::Or
+  : (Instruction::BinaryOps)0);
 if (InvertCond) {
   if (BOpc == Instruction::And)
 BOpc = Instruction::Or;
@@ -443,11 +448,11 @@ void IRTranslator::findMergedConditions(
   }
 
   // If this node is not part of the or/and tree, emit it as a branch.
-  if (!BOp || !(isa(BO

[llvm-branch-commits] [llvm] a2513cb - remove pessimizing moves (reported by gcc 10)

2020-12-31 Thread Nuno Lopes via llvm-branch-commits

Author: Nuno Lopes
Date: 2020-12-31T20:35:56Z
New Revision: a2513cb8655e0aea4baffb4391e946ad3e56d883

URL: 
https://github.com/llvm/llvm-project/commit/a2513cb8655e0aea4baffb4391e946ad3e56d883
DIFF: 
https://github.com/llvm/llvm-project/commit/a2513cb8655e0aea4baffb4391e946ad3e56d883.diff

LOG: remove pessimizing moves (reported by gcc 10)

Added: 


Modified: 
llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h

Removed: 




diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h 
b/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
index 1c8b8e0bc922..63db9d4942ba 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
@@ -1510,20 +1510,20 @@ class SingleThreadedRPCEndpoint
 Args...)) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return std::move(Err);
+  return Err;
 }
 
 if (auto Err = this->C.send()) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return std::move(Err);
+  return Err;
 }
 
 while (!ReceivedResponse) {
   if (auto Err = this->handleOne()) {
 detail::ResultTraits::consumeAbandoned(
 std::move(Result));
-return std::move(Err);
+return Err;
   }
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] d974ac0 - [IRSim] Letting gep instructions be legal for similarity identification.

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T14:41:14-06:00
New Revision: d974ac0224dec34b95fb1be8c61bd8b524698bcd

URL: 
https://github.com/llvm/llvm-project/commit/d974ac0224dec34b95fb1be8c61bd8b524698bcd
DIFF: 
https://github.com/llvm/llvm-project/commit/d974ac0224dec34b95fb1be8c61bd8b524698bcd.diff

LOG: [IRSim] Letting gep instructions be legal for similarity identification.

GetElementPtr instructions require the extra check that all operands
after the first must only be constants and be exactly the same to be
considered similar.

Tests are found in unittests/Analysis/IRSimilarityIdentifierTest.cpp.

Added: 


Modified: 
llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
llvm/lib/Analysis/IRSimilarityIdentifier.cpp
llvm/test/Transforms/IROutliner/illegal-gep.ll
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp

Removed: 




diff  --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h 
b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
index 99a5fcb3a578..a3004ca0dc59 100644
--- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
+++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
@@ -396,10 +396,6 @@ struct IRInstructionMapper {
 // analyzed for similarity as it has no bearing on the outcome of the
 // program.
 InstrType visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) { return Invisible; 
}
-// TODO: Handle GetElementPtrInsts
-InstrType visitGetElementPtrInst(GetElementPtrInst &GEPI) {
-  return Illegal;
-}
 // TODO: Handle specific intrinsics.
 InstrType visitIntrinsicInst(IntrinsicInst &II) { return Illegal; }
 // TODO: Handle CallInsts.

diff  --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp 
b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
index 141c1e0a5d03..c276e3f28d73 100644
--- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
+++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
@@ -83,27 +83,53 @@ bool IRSimilarity::isClose(const IRInstructionData &A,
 
   // Check if we are performing the same sort of operation on the same types
   // but not on the same values.
-  if (A.Inst->isSameOperationAs(B.Inst))
-return true;
+  if (!A.Inst->isSameOperationAs(B.Inst)) {
+// If there is a predicate, this means that either there is a swapped
+// predicate, or that the types are 
diff erent, we want to make sure that
+// the predicates are equivalent via swapping.
+if (isa(A.Inst) && isa(B.Inst)) {
+
+  if (A.getPredicate() != B.getPredicate())
+return false;
+
+  // If the predicates are the same via swap, make sure that the types are
+  // still the same.
+  auto ZippedTypes = zip(A.OperVals, B.OperVals);
+
+  return all_of(
+  ZippedTypes, [](std::tuple R) {
+return std::get<0>(R)->getType() == std::get<1>(R)->getType();
+  });
+}
 
-  // If there is a predicate, this means that either there is a swapped
-  // predicate, or that the types are 
diff erent, we want to make sure that
-  // the predicates are equivalent via swapping.
-  if (isa(A.Inst) && isa(B.Inst)) {
+return false;
+  }
+
+  // Since any GEP Instruction operands after the first operand cannot be
+  // defined by a register, we must make sure that the operands after the first
+  // are the same in the two instructions
+  if (auto *GEP = dyn_cast(A.Inst)) {
+auto *OtherGEP = cast(B.Inst);
 
-if (A.getPredicate() != B.getPredicate())
+// If the instructions do not have the same inbounds restrictions, we do
+// not consider them the same.
+if (GEP->isInBounds() != OtherGEP->isInBounds())
   return false;
 
-// If the predicates are the same via swap, make sure that the types are
-// still the same.
-auto ZippedTypes = zip(A.OperVals, B.OperVals);
+auto ZippedOperands = zip(GEP->indices(), OtherGEP->indices());
 
-return all_of(ZippedTypes, [](std::tuple R) {
-  return std::get<0>(R)->getType() == std::get<1>(R)->getType();
-});
+auto ZIt = ZippedOperands.begin();
+
+// We increment here since we do not care about the first instruction,
+// we only care about the following operands since they must be the
+// exact same to be considered similar.
+return std::all_of(++ZIt, ZippedOperands.end(),
+   [](std::tuple R) {
+ return std::get<0>(R) == std::get<1>(R);
+   });
   }
 
-  return false;
+  return true;
 }
 
 // TODO: This is the same as the MachineOutliner, and should be consolidated

diff  --git a/llvm/test/Transforms/IROutliner/illegal-gep.ll 
b/llvm/test/Transforms/IROutliner/illegal-gep.ll
index a625106105b0..5f009617c4b3 100644
--- a/llvm/test/Transforms/IROutliner/illegal-gep.ll
+++ b/llvm/test/Transforms/IROutliner/illegal-gep.ll
@@ -12,7 +12,8 @@ define void @function1(%struct.ST* %s, i64 %t) {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A:%.*]] = alloca i3

[llvm-branch-commits] [llvm] 3c60e9b - Add tests for D93943 (NFC)

2020-12-31 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-01T05:59:52+09:00
New Revision: 3c60e9bac86804a32bf515b9381c91fb64d769f8

URL: 
https://github.com/llvm/llvm-project/commit/3c60e9bac86804a32bf515b9381c91fb64d769f8
DIFF: 
https://github.com/llvm/llvm-project/commit/3c60e9bac86804a32bf515b9381c91fb64d769f8.diff

LOG: Add tests for D93943 (NFC)

Added: 


Modified: 
llvm/test/Transforms/SimplifyCFG/switch_create.ll

Removed: 




diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_create.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
index cc7a48904482..10689a03c398 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_create.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
@@ -469,6 +469,29 @@ define i32 @test10_select(i32 %mode, i1 %Cond) {
 ; CHECK-NEXT:[[A:%.*]] = icmp ne i32 [[MODE:%.*]], 0
 ; CHECK-NEXT:[[B:%.*]] = icmp ne i32 [[MODE]], 51
 ; CHECK-NEXT:[[C:%.*]] = select i1 [[A]], i1 [[B]], i1 false
+; CHECK-NEXT:[[D:%.*]] = select i1 [[C]], i1 [[COND:%.*]], i1 false
+; CHECK-NEXT:[[SPEC_SELECT:%.*]] = select i1 [[D]], i32 123, i32 324
+; CHECK-NEXT:ret i32 [[SPEC_SELECT]]
+;
+  %A = icmp ne i32 %mode, 0
+  %B = icmp ne i32 %mode, 51
+  %C = select i1 %A, i1 %B, i1 false
+  %D = select i1 %C, i1 %Cond, i1 false
+  br i1 %D, label %T, label %F
+T:
+  ret i32 123
+F:
+  ret i32 324
+
+}
+
+; TODO: %Cond doesn't need freeze
+define i32 @test10_select_and(i32 %mode, i1 %Cond) {
+; CHECK-LABEL: @test10_select_and(
+; CHECK-NEXT:  T:
+; CHECK-NEXT:[[A:%.*]] = icmp ne i32 [[MODE:%.*]], 0
+; CHECK-NEXT:[[B:%.*]] = icmp ne i32 [[MODE]], 51
+; CHECK-NEXT:[[C:%.*]] = select i1 [[A]], i1 [[B]], i1 false
 ; CHECK-NEXT:[[D:%.*]] = and i1 [[C]], [[COND:%.*]]
 ; CHECK-NEXT:[[SPEC_SELECT:%.*]] = select i1 [[D]], i32 123, i32 324
 ; CHECK-NEXT:ret i32 [[SPEC_SELECT]]
@@ -485,6 +508,28 @@ F:
 
 }
 
+define i32 @test10_select_nofreeze(i32 %mode, i1 noundef %Cond) {
+; CHECK-LABEL: @test10_select_nofreeze(
+; CHECK-NEXT:  T:
+; CHECK-NEXT:[[A:%.*]] = icmp ne i32 [[MODE:%.*]], 0
+; CHECK-NEXT:[[B:%.*]] = icmp ne i32 [[MODE]], 51
+; CHECK-NEXT:[[C:%.*]] = select i1 [[A]], i1 [[B]], i1 false
+; CHECK-NEXT:[[D:%.*]] = select i1 [[C]], i1 [[COND:%.*]], i1 false
+; CHECK-NEXT:[[SPEC_SELECT:%.*]] = select i1 [[D]], i32 123, i32 324
+; CHECK-NEXT:ret i32 [[SPEC_SELECT]]
+;
+  %A = icmp ne i32 %mode, 0
+  %B = icmp ne i32 %mode, 51
+  %C = select i1 %A, i1 %B, i1 false
+  %D = select i1 %C, i1 %Cond, i1 false
+  br i1 %D, label %T, label %F
+T:
+  ret i32 123
+F:
+  ret i32 324
+
+}
+
 ; PR8780
 define i32 @test11(i32 %bar) nounwind {
 ; CHECK-LABEL: @test11(



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 14dc69b - Revert "remove pessimizing moves (reported by gcc 10)"

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T15:14:11-06:00
New Revision: 14dc69b09218bb580069eb547bb16ab0c43db6d4

URL: 
https://github.com/llvm/llvm-project/commit/14dc69b09218bb580069eb547bb16ab0c43db6d4
DIFF: 
https://github.com/llvm/llvm-project/commit/14dc69b09218bb580069eb547bb16ab0c43db6d4.diff

LOG: Revert "remove pessimizing moves (reported by gcc 10)"

Causing multiple different buildbots to fail with similar errors to:
http://lab.llvm.org:8011/#/builders/84/builds/3719/
http://lab.llvm.org:8011/#/builders/21/builds/5863/

This reverts commit a2513cb8655e0aea4baffb4391e946ad3e56d883.

Added: 


Modified: 
llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h

Removed: 




diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h 
b/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
index 63db9d4942bac..1c8b8e0bc922e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
@@ -1510,20 +1510,20 @@ class SingleThreadedRPCEndpoint
 Args...)) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return Err;
+  return std::move(Err);
 }
 
 if (auto Err = this->C.send()) {
   detail::ResultTraits::consumeAbandoned(
   std::move(Result));
-  return Err;
+  return std::move(Err);
 }
 
 while (!ReceivedResponse) {
   if (auto Err = this->handleOne()) {
 detail::ResultTraits::consumeAbandoned(
 std::move(Result));
-return Err;
+return std::move(Err);
   }
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] d1fd723 - Refactor how -fno-semantic-interposition sets dso_local on default visibility external linkage definitions

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T13:59:45-08:00
New Revision: d1fd72343c6ff58a3b66bc0df56fed9ac21e4056

URL: 
https://github.com/llvm/llvm-project/commit/d1fd72343c6ff58a3b66bc0df56fed9ac21e4056
DIFF: 
https://github.com/llvm/llvm-project/commit/d1fd72343c6ff58a3b66bc0df56fed9ac21e4056.diff

LOG: Refactor how -fno-semantic-interposition sets dso_local on default 
visibility external linkage definitions

The idea is that the CC1 default for ELF should set dso_local on default
visibility external linkage definitions in the default -mrelocation-model pic
mode (-fpic/-fPIC) to match COFF/Mach-O and make output IR similar.

The refactoring is made available by 2820a2ca3a0e69c3f301845420e00672251b.

Currently only x86 supports local aliases. We move the decision to the driver.
There are three CC1 states:

* -fsemantic-interposition: make some linkages interposable and make default 
visibility external linkage definitions dso_preemptable.
* (default): selected if the target supports .Lfoo$local: make default 
visibility external linkage definitions dso_local
* -fhalf-no-semantic-interposition: if neither option is set or the target does 
not support .Lfoo$local: like -fno-semantic-interposition but local aliases are 
not used. So references can be interposed if not optimized out.

Add -fhalf-no-semantic-interposition to a few tests using the half-based 
semantic interposition behavior.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
clang/test/CodeGen/semantic-interposition.c

clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/diamond-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/inline-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/no-alias-when-dso-local.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/override-pure-virtual-method.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/overriden-virtual-function.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-flag.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
clang/test/Driver/fsemantic-interposition.c
llvm/include/llvm/IR/Module.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/IR/Module.cpp

Removed: 
clang/test/CodeGen/semantic-interposition-no.c



diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index cc5eb939dbd2..963fde5f3ad4 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -322,7 +322,8 @@ ENUM_LANGOPT(ExternDeclDLLImportVisibility, Visibility, 3, 
DefaultVisibility,
 ENUM_LANGOPT(ExternDeclNoDLLStorageClassVisibility, Visibility, 3, 
HiddenVisibility,
  "visibility for external declarations without an explicit DLL 
storage class [-fvisibility-from-dllstorageclass]")
 BENIGN_LANGOPT(SemanticInterposition, 1, 0, "semantic interposition")
-BENIGN_LANGOPT(ExplicitNoSemanticInterposition, 1, 0, "explicitly no semantic 
interposition")
+BENIGN_LANGOPT(HalfNoSemanticInterposition, 1, 0,
+   "Like -fno-semantic-interposition but don't use local aliases")
 ENUM_LANGOPT(StackProtector, StackProtectorMode, 2, SSPOff,
  "stack protector mode")
 ENUM_LANGOPT(TrivialAutoVarInit, TrivialAutoVarInitKind, 2, 
TrivialAutoVarInitKind::Uninitialized,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index af209eb9089d..9a851f63a663 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3793,7 +3793,7 @@ defm ipa_cp : BooleanFFlag<"ipa-cp">,
 Group;
 defm ivopts : BooleanFFlag<"ivopts">, 
Group;
 def fsemantic_interposition : Flag<["-"], "fsemantic-interposition">, 
Group, Flags<[CC1Option]>;
-def fno_semantic_interposition: Flag<["-"], "fno-semantic-interposition">, 
Group, Flags<[CC1Option]>;
+def fno_semantic_interposition: Flag<["-"], "fno-semantic-interposition">, 
Group;
 defm non_call_exceptions : BooleanFFlag<"non-call-exceptions">, 
Group;
 defm peel_loops : BooleanFFlag<"peel-loops">, 
Group;
 defm permissive : BooleanFFlag<"permissive">, Group;
@@ -4722,6 +4722,8 @@ def pic_level : Separate<["-"], "pic-level">,
   HelpText<"Value for __PI

[llvm-branch-commits] [clang] 219d00e - [test] Make ELF tests immune to dso_local/dso_preemptable/(none) differences

2020-12-31 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2020-12-31T13:59:44-08:00
New Revision: 219d00e0d90941d3e54fc711ea1e7b5e4b5b4335

URL: 
https://github.com/llvm/llvm-project/commit/219d00e0d90941d3e54fc711ea1e7b5e4b5b4335
DIFF: 
https://github.com/llvm/llvm-project/commit/219d00e0d90941d3e54fc711ea1e7b5e4b5b4335.diff

LOG: [test] Make ELF tests immune to dso_local/dso_preemptable/(none) 
differences

ELF -cc1 -mrelocation-model pic will default to no semantic interposition plus
setting dso_local on default visibility external linkage definitions, so that
COFF, Mach-O and ELF output will be similar.

This patch makes tests immune to the differences.

Added: 


Modified: 
clang/test/CodeGenCUDA/lambda-reference-var.cu
clang/test/CodeGenCXX/default_calling_conv.cpp
clang/test/Driver/hip-fpie-option.hip
clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/lambda-reference-var.cu 
b/clang/test/CodeGenCUDA/lambda-reference-var.cu
index 44b012956507..2c62b0a94beb 100644
--- a/clang/test/CodeGenCUDA/lambda-reference-var.cu
+++ b/clang/test/CodeGenCUDA/lambda-reference-var.cu
@@ -47,7 +47,7 @@ __device__ void dev_capture_dev_ref_by_ref(int *out) {
   [&](){ ref++; *out = ref;}();
 }
 
-// DEV-LABEL: define void @_Z7dev_refPi(
+// DEV-LABEL: define{{.*}} void @_Z7dev_refPi(
 // DEV: %[[VAL:.*]] = load i32, i32* addrspacecast (i32 addrspace(1)* 
@global_device_var to i32*)
 // DEV: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
 // DEV: store i32 %[[VAL2]], i32* addrspacecast (i32 addrspace(1)* 
@global_device_var to i32*)
@@ -94,7 +94,7 @@ void host_capture_host_ref_by_ref(int *out) {
   [&](){ ref++; *out = ref;}();
 }
 
-// HOST-LABEL: define void @_Z8host_refPi(
+// HOST-LABEL: define{{.*}} void @_Z8host_refPi(
 // HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
 // HOST: %[[VAL2:.*]] = add nsw i32 %[[VAL]], 1
 // HOST: store i32 %[[VAL2]], i32* @global_host_var
@@ -120,7 +120,7 @@ void host_lambda_ref(int *out) {
   }();
 }
 
-// HOST-LABEL: define void @_Z28dev_capture_host_ref_by_copyPi(
+// HOST-LABEL: define{{.*}} void @_Z28dev_capture_host_ref_by_copyPi(
 // HOST: %[[CAP:.*]] = getelementptr inbounds %[[T3]], %[[T3]]* %{{.*}}, i32 
0, i32 1
 // HOST: %[[VAL:.*]] = load i32, i32* @global_host_var
 // HOST: store i32 %[[VAL]], i32* %[[CAP]]

diff  --git a/clang/test/CodeGenCXX/default_calling_conv.cpp 
b/clang/test/CodeGenCXX/default_calling_conv.cpp
index d1f9571e0d56..e3d7ac429a60 100644
--- a/clang/test/CodeGenCXX/default_calling_conv.cpp
+++ b/clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -29,7 +29,7 @@ void __attribute__((fastcall)) test3() {}
 // ALL: define{{.*}} x86_stdcallcc void @_Z5test4v
 void __attribute__((stdcall)) test4() {}
 
-// ALL: define  x86_vectorcallcc void @_Z5test5v
+// ALL: define{{.*}} x86_vectorcallcc void @_Z5test5v
 void __attribute__((vectorcall)) test5() {}
 
 // ALL: define{{.*}} x86_regcallcc void @_Z17__regcall3__test6v

diff  --git a/clang/test/Driver/hip-fpie-option.hip 
b/clang/test/Driver/hip-fpie-option.hip
index 2b433cd5a2c2..2e296a099dea 100644
--- a/clang/test/Driver/hip-fpie-option.hip
+++ b/clang/test/Driver/hip-fpie-option.hip
@@ -31,8 +31,9 @@
 // RUN:   -fPIE \
 // RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
 
-// DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* 
"-mrelocation-model" "pic" "-pic-level" "[1|2]" "-mframe-pointer=all"}}
+// DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* 
"-mrelocation-model" "pic" "-pic-level" "[1|2]".* "-mframe-pointer=all"}}
 // HOST-STATIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-mrelocation-model" "static"}}
-// HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all"}}
+// HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-mrelocation-model" "pic" "-pic-level" "2"}}
+// HOST-PIC-NOT: "-pic-is-pie"
 // HOST-PIE-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}}
 // DEV-NOT: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-pic-is-pie"}}

diff  --git a/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp 
b/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
index 91a9c2af73da..496ac07d9fa2 100644
--- a/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
@@ -18,7 +18,7 @@
 // DEVICE-DAG: [[C_ADDR:.+]] = internal global i32 0,
 // DEVICE-DAG: [[CD_ADDR:@.+]] ={{ hidden | }}global %struct.S zeroinitializer,
 // HOST-DAG: @[[C_ADDR:.+]] = internal global i32 0,
-// HOST-DAG: @[[CD_ADDR:.+]] ={{ hidden | }}global %struct.S zeroinitializer,
+// HOST-DAG: @[[CD_ADDR:.+]] ={{( hidden | dso_local)?}} global %struct.S 
zeroinitializer,
 
 #pragma omp declare target
 i

[llvm-branch-commits] [llvm] eaab711 - [Analysis] reduce code for matching min/max; NFC

2020-12-31 Thread Sanjay Patel via llvm-branch-commits

Author: Sanjay Patel
Date: 2020-12-31T17:19:37-05:00
New Revision: eaab71106b81031d272acfc6987e99e8b65cbe6c

URL: 
https://github.com/llvm/llvm-project/commit/eaab71106b81031d272acfc6987e99e8b65cbe6c
DIFF: 
https://github.com/llvm/llvm-project/commit/eaab71106b81031d272acfc6987e99e8b65cbe6c.diff

LOG: [Analysis] reduce code for matching min/max; NFC

This might also make it easier to adapt if we want
to match min/max intrinsics rather than cmp+sel idioms.

The 'const' part is to potentially avoid confusion
in calling code. There's some surprising and possibly
wrong behavior related to matching min/max reductions
differently than other reductions.

Added: 


Modified: 
llvm/include/llvm/Analysis/IVDescriptors.h
llvm/lib/Analysis/IVDescriptors.cpp

Removed: 




diff  --git a/llvm/include/llvm/Analysis/IVDescriptors.h 
b/llvm/include/llvm/Analysis/IVDescriptors.h
index e736adf899b8..30216e22fc34 100644
--- a/llvm/include/llvm/Analysis/IVDescriptors.h
+++ b/llvm/include/llvm/Analysis/IVDescriptors.h
@@ -96,15 +96,15 @@ class RecurrenceDescriptor {
 : IsRecurrence(true), PatternLastInst(I), MinMaxKind(K),
   UnsafeAlgebraInst(UAI) {}
 
-bool isRecurrence() { return IsRecurrence; }
+bool isRecurrence() const { return IsRecurrence; }
 
-bool hasUnsafeAlgebra() { return UnsafeAlgebraInst != nullptr; }
+bool hasUnsafeAlgebra() const { return UnsafeAlgebraInst != nullptr; }
 
-Instruction *getUnsafeAlgebraInst() { return UnsafeAlgebraInst; }
+Instruction *getUnsafeAlgebraInst() const { return UnsafeAlgebraInst; }
 
-MinMaxRecurrenceKind getMinMaxKind() { return MinMaxKind; }
+MinMaxRecurrenceKind getMinMaxKind() const { return MinMaxKind; }
 
-Instruction *getPatternInst() { return PatternLastInst; }
+Instruction *getPatternInst() const { return PatternLastInst; }
 
   private:
 // Is this instruction a recurrence candidate.
@@ -134,10 +134,11 @@ class RecurrenceDescriptor {
   /// Returns true if all uses of the instruction I is within the Set.
   static bool areAllUsesIn(Instruction *I, SmallPtrSetImpl 
&Set);
 
-  /// Returns a struct describing if the instruction if the instruction is a
+  /// Returns a struct describing if the instruction is a
   /// Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y)
-  /// or max(X, Y).
-  static InstDesc isMinMaxSelectCmpPattern(Instruction *I, InstDesc &Prev);
+  /// or max(X, Y). \p Prev is specifies the description of an already 
processed
+  /// select instruction, so its corresponding cmp can be matched to it.
+  static InstDesc isMinMaxSelectCmpPattern(Instruction *I, const InstDesc 
&Prev);
 
   /// Returns a struct describing if the instruction is a
   /// Select(FCmp(X, Y), (Z = X op PHINode), PHINode) instruction pattern.

diff  --git a/llvm/lib/Analysis/IVDescriptors.cpp 
b/llvm/lib/Analysis/IVDescriptors.cpp
index d9756512de77..eac6f3cb30f8 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -456,53 +456,42 @@ bool RecurrenceDescriptor::AddReductionVar(PHINode *Phi, 
RecurrenceKind Kind,
   return true;
 }
 
-/// Returns true if the instruction is a Select(ICmp(X, Y), X, Y) instruction
-/// pattern corresponding to a min(X, Y) or max(X, Y).
 RecurrenceDescriptor::InstDesc
-RecurrenceDescriptor::isMinMaxSelectCmpPattern(Instruction *I, InstDesc &Prev) 
{
-
-  assert((isa(I) || isa(I) || isa(I)) &&
- "Expect a select instruction");
-  Instruction *Cmp = nullptr;
-  SelectInst *Select = nullptr;
+RecurrenceDescriptor::isMinMaxSelectCmpPattern(Instruction *I,
+   const InstDesc &Prev) {
+  assert((isa(I) || isa(I)) &&
+ "Expected a cmp or select instruction");
 
   // We must handle the select(cmp()) as a single instruction. Advance to the
   // select.
-  if ((Cmp = dyn_cast(I)) || (Cmp = dyn_cast(I))) {
-if (!Cmp->hasOneUse() || !(Select = 
dyn_cast(*I->user_begin(
-  return InstDesc(false, I);
-return InstDesc(Select, Prev.getMinMaxKind());
+  CmpInst::Predicate Pred;
+  if (match(I, m_OneUse(m_Cmp(Pred, m_Value(), m_Value() {
+if (auto *Select = dyn_cast(*I->user_begin()))
+  return InstDesc(Select, Prev.getMinMaxKind());
   }
 
-  // Only handle single use cases for now.
-  if (!(Select = dyn_cast(I)))
+  // Only match select with single use cmp condition.
+  if (!match(I, m_Select(m_OneUse(m_Cmp(Pred, m_Value(), m_Value())), 
m_Value(),
+ m_Value(
 return InstDesc(false, I);
-  if (!(Cmp = dyn_cast(I->getOperand(0))) &&
-  !(Cmp = dyn_cast(I->getOperand(0
-return InstDesc(false, I);
-  if (!Cmp->hasOneUse())
-return InstDesc(false, I);
-
-  Value *CmpLeft;
-  Value *CmpRight;
 
   // Look for a min/max pattern.
-  if (m_UMin(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
-return InstDesc(Select, MRK_U

[llvm-branch-commits] [mlir] 8d541a1 - [mlir][shape] Add shape.lib attribute

2020-12-31 Thread Jacques Pienaar via llvm-branch-commits

Author: Jacques Pienaar
Date: 2020-12-31T14:46:08-08:00
New Revision: 8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092

URL: 
https://github.com/llvm/llvm-project/commit/8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092
DIFF: 
https://github.com/llvm/llvm-project/commit/8d541a1fbe6d92a3fadf6d7d8e8209ed6c76e092.diff

LOG: [mlir][shape] Add shape.lib attribute

Enable querying shape function library ops from the module. Currently
supports singular or array of them (as long as array has all unique ops
in mappings). The preferred canonical form would have one library, but
given the invariant on the mapping, this can easily be achieved by a
simple merging pass.

Preferred the attribute approach vs naming convention as these could be
added in multiple different ways.

Added: 


Modified: 
mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/test/Analysis/test-shape-fn-report.mlir
mlir/test/Dialect/Shape/invalid.mlir
mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp

Removed: 




diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td 
b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
index a7868e74c65f..1cccb59dfbb9 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
@@ -37,6 +37,7 @@ def ShapeDialect : Dialect {
   let cppNamespace = "::mlir::shape";
 
   let hasConstantMaterializer = 1;
+  let hasOperationAttrVerify = 1;
 }
 
 def Shape_ShapeType : DialectTypehasTrait())
+  return op->emitError(
+  "shape.lib attribute may only be on op implementing SymbolTable");
+
+if (auto symbolRef = attribute.second.dyn_cast()) {
+  auto *symbol = SymbolTable::lookupSymbolIn(op, symbolRef);
+  if (!symbol)
+return op->emitError("shape function library ")
+   << symbolRef << " not found";
+  return isa(symbol)
+ ? success()
+ : op->emitError()
+   << symbolRef << " required to be shape function 
library";
+}
+
+if (auto arr = attribute.second.dyn_cast()) {
+  // Verify all entries are function libraries and mappings in libraries
+  // refer to unique ops.
+  DenseSet key;
+  for (auto it : arr) {
+if (!it.isa())
+  return op->emitError(
+  "only SymbolRefAttr allowed in shape.lib attribute array");
+
+auto shapeFnLib = dyn_cast(
+SymbolTable::lookupSymbolIn(op, it.cast()));
+if (!shapeFnLib)
+  return op->emitError()
+ << it << " does not refer to FunctionLibraryOp";
+for (auto mapping : shapeFnLib.mapping()) {
+  if (!key.insert(mapping.first).second) {
+return op->emitError("only one op to shape mapping allowed, found "
+ "multiple for `")
+   << mapping.first << "`";
+  }
+}
+  }
+  return success();
+}
+
+return op->emitError("only SymbolRefAttr or array of SymbolRefAttrs "
+ "allowed as shape.lib attribute");
+  }
+  return success();
+}
+
 
//===--===//
 // AnyOp
 
//===--===//

diff  --git a/mlir/test/Analysis/test-shape-fn-report.mlir 
b/mlir/test/Analysis/test-shape-fn-report.mlir
index ad5c8e64a1b7..b01593531502 100644
--- a/mlir/test/Analysis/test-shape-fn-report.mlir
+++ b/mlir/test/Analysis/test-shape-fn-report.mlir
@@ -1,5 +1,7 @@
 // RUN: mlir-opt %s --test-shape-function-report -verify-diagnostics
 
+module attributes {shape.lib = [@shape_lib]} {
+
 // expected-remark@+1 {{associated shape function: same_result_shape}}
 func @tanh(%arg: tensor<10x20xf32>) -> tensor<10x20xf32>
 attributes {shape.function = @shape_lib::@same_result_shape} {
@@ -20,3 +22,5 @@ shape.function_library @shape_lib {
 } mapping {
   test.same_operand_result_type = @same_result_shape
 }
+
+}

diff  --git a/mlir/test/Dialect/Shape/invalid.mlir 
b/mlir/test/Dialect/Shape/invalid.mlir
index eb0ae5ae05a9..d2f5af2f7b30 100644
--- a/mlir/test/Dialect/Shape/invalid.mlir
+++ b/mlir/test/Dialect/Shape/invalid.mlir
@@ -154,3 +154,95 @@ func @broadcast(%arg0 : !shape.shape, %arg1 : 
tensor) -> tensor -> tensor
   return %result : tensor
 }
+
+// -
+
+// Test using an unsupported shape.lib attribute type.
+
+// expected-error@+1 {{only SymbolRefAttr allowed in shape.lib attribute 
array}}
+module attributes {shape.lib = [@shape_lib, "shape_lib"]} {
+
+shape.function_library @shape_lib {
+  // Test shape function that returns the shape of input arg as result shape.
+  func @same_result_shape(%arg: !shape.value_shape) -> !shape.shape {
+%0 = shape.shape_of %arg : !shape.value_shape -> !shape.shape
+return %0 : !shape.shape
+  }
+} mapping {
+  test.same_operand_result_type 

[llvm-branch-commits] [llvm] b6b1006 - [IRSim][IROutliner] Allowing GEP instructions to be outlined.

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T16:54:17-06:00
New Revision: b6b1006f0719481dfb785f281afb5b371c19f00c

URL: 
https://github.com/llvm/llvm-project/commit/b6b1006f0719481dfb785f281afb5b371c19f00c
DIFF: 
https://github.com/llvm/llvm-project/commit/b6b1006f0719481dfb785f281afb5b371c19f00c.diff

LOG: [IRSim][IROutliner] Allowing GEP instructions to be outlined.

We outline what the IRSimilarityIdentifier deems GEP Instructions to be
similar.  In this case, the types must be the same, and the operand
values after the first indexing operand must be the exact same.

Tests:
Removing test/Transforms/IROutliner/illegal-gep.ll
Adding test/Transforms/IROutliner/outlining-gep.ll

Reviewers: jroelofs, paquette

Differential Revision: https://reviews.llvm.org/D87317

Added: 
llvm/test/Transforms/IROutliner/outlining-gep.ll

Modified: 
llvm/include/llvm/Transforms/IPO/IROutliner.h

Removed: 
llvm/test/Transforms/IROutliner/illegal-gep.ll



diff  --git a/llvm/include/llvm/Transforms/IPO/IROutliner.h 
b/llvm/include/llvm/Transforms/IPO/IROutliner.h
index 947a70866b04..fef02b18b7c3 100644
--- a/llvm/include/llvm/Transforms/IPO/IROutliner.h
+++ b/llvm/include/llvm/Transforms/IPO/IROutliner.h
@@ -318,8 +318,6 @@ class IROutliner {
 // analyzed for similarity as it has no bearing on the outcome of the
 // program.
 bool visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) { return true; }
-// TODO: Handle GetElementPtrInsts
-bool visitGetElementPtrInst(GetElementPtrInst &GEPI) { return false; }
 // TODO: Handle specific intrinsics individually from those that can be
 // handled.
 bool IntrinsicInst(IntrinsicInst &II) { return false; }

diff  --git a/llvm/test/Transforms/IROutliner/illegal-gep.ll 
b/llvm/test/Transforms/IROutliner/illegal-gep.ll
deleted file mode 100644
index 5f009617c4b3..
--- a/llvm/test/Transforms/IROutliner/illegal-gep.ll
+++ /dev/null
@@ -1,50 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -verify -iroutliner -ir-outlining-no-cost < %s | FileCheck %s
-
-; This test checks to make sure that we do not outline getelementptr
-; instructions since we must make extra checks on the final operands.
-
-%struct.RT = type { i8, [10 x [20 x i32]], i8 }
-%struct.ST = type { i32, double, %struct.RT }
-
-define void @function1(%struct.ST* %s, i64 %t) {
-; CHECK-LABEL: @function1(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
-; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
-; CHECK-NEXT:store i32 2, i32* [[A]], align 4
-; CHECK-NEXT:store i32 3, i32* [[B]], align 4
-; CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], 
%struct.ST* [[S:%.*]], i64 1
-; CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ST]], 
%struct.ST* [[S]], i64 [[T:%.*]]
-; CHECK-NEXT:ret void
-;
-entry:
-  %a = alloca i32, align 4
-  %b = alloca i32, align 4
-  store i32 2, i32* %a, align 4
-  store i32 3, i32* %b, align 4
-  %0 = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1
-  %1 = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 %t
-  ret void
-}
-
-define void @function2(%struct.ST* %s, i64 %t) {
-; CHECK-LABEL: @function2(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
-; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
-; CHECK-NEXT:store i32 2, i32* [[A]], align 4
-; CHECK-NEXT:store i32 3, i32* [[B]], align 4
-; CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], 
%struct.ST* [[S:%.*]], i64 1
-; CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ST]], 
%struct.ST* [[S]], i64 [[T:%.*]]
-; CHECK-NEXT:ret void
-;
-entry:
-  %a = alloca i32, align 4
-  %b = alloca i32, align 4
-  store i32 2, i32* %a, align 4
-  store i32 3, i32* %b, align 4
-  %0 = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1
-  %1 = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 %t
-  ret void
-}

diff  --git a/llvm/test/Transforms/IROutliner/outlining-gep.ll 
b/llvm/test/Transforms/IROutliner/outlining-gep.ll
new file mode 100644
index ..3d99e5c8caa3
--- /dev/null
+++ b/llvm/test/Transforms/IROutliner/outlining-gep.ll
@@ -0,0 +1,68 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -verify -iroutliner -ir-outlining-no-cost < %s | FileCheck %s
+
+; This test checks to make sure that we outline getelementptr instructions only
+; when all the operands after the first are the exact same. In this case, we
+; outline from the first two functions, but not the third.
+
+%struct.RT = type { i8, [10 x [20 x i32]], i8 }
+%struct.ST = type { i32, double, %struct.RT }
+
+define void @function1(%struct.ST* %s, i64 %t) {
+; CHECK-LABEL: @function1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
+; CHECK-NEXT

[llvm-branch-commits] [llvm] c1b825d - [SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve DomTree, part 1

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:22+03:00
New Revision: c1b825d4b8a68178613972a50088b2b73105e91e

URL: 
https://github.com/llvm/llvm-project/commit/c1b825d4b8a68178613972a50088b2b73105e91e
DIFF: 
https://github.com/llvm/llvm-project/commit/c1b825d4b8a68178613972a50088b2b73105e91e.diff

LOG: [SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve 
DomTree, part 1

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll
llvm/test/Transforms/JumpThreading/lvi-tristate.ll
llvm/test/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
llvm/test/Transforms/SimplifyCFG/2006-08-03-Crash.ll
llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll
llvm/test/Transforms/SimplifyCFG/DeadSetCC.ll
llvm/test/Transforms/SimplifyCFG/X86/MagicPointer.ll
llvm/test/Transforms/SimplifyCFG/preserve-branchweights-partial.ll
llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 7e49d3a1524c..f1e6c50130c8 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1088,11 +1088,14 @@ bool 
SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
   SmallSetVector FailBlocks;
   if (!SafeToMergeTerminators(TI, PTI, &FailBlocks)) {
 for (auto *Succ : FailBlocks) {
-  if (!SplitBlockPredecessors(Succ, TI->getParent(), ".fold.split"))
+  if (!SplitBlockPredecessors(Succ, TI->getParent(), ".fold.split",
+  DTU ? &DTU->getDomTree() : nullptr))
 return false;
 }
   }
 
+  std::vector Updates;
+
   // Figure out which 'cases' to copy from SI to PSI.
   std::vector BBCases;
   BasicBlock *BBDefault = GetValueEqualityComparisonCases(TI, BBCases);
@@ -1156,6 +1159,7 @@ bool 
SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
 // Reconstruct the new switch statement we will be building.
 if (PredDefault != BBDefault) {
   PredDefault->removePredecessor(Pred);
+  Updates.push_back({DominatorTree::Delete, Pred, PredDefault});
   PredDefault = BBDefault;
   NewSuccessors.push_back(BBDefault);
 }
@@ -1232,8 +1236,10 @@ bool 
SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
   // Okay, at this point, we know which new successor Pred will get.  Make
   // sure we update the number of entries in the PHI nodes for these
   // successors.
-  for (BasicBlock *NewSuccessor : NewSuccessors)
+  for (BasicBlock *NewSuccessor : NewSuccessors) {
 AddPredecessorToBlock(NewSuccessor, Pred, BB);
+Updates.push_back({DominatorTree::Insert, Pred, NewSuccessor});
+  }
 
   Builder.SetInsertPoint(PTI);
   // Convert pointer to int before we switch.
@@ -1272,10 +1278,20 @@ bool 
SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
 InfLoopBlock = BasicBlock::Create(BB->getContext(), "infloop",
   BB->getParent());
 BranchInst::Create(InfLoopBlock, InfLoopBlock);
+Updates.push_back(
+{DominatorTree::Insert, InfLoopBlock, InfLoopBlock});
   }
   NewSI->setSuccessor(i, InfLoopBlock);
 }
 
+  if (InfLoopBlock) {
+Updates.push_back({DominatorTree::Delete, Pred, BB});
+Updates.push_back({DominatorTree::Insert, Pred, InfLoopBlock});
+  }
+
+  if (DTU)
+DTU->applyUpdatesPermissive(Updates);
+
   Changed = true;
 }
   }

diff  --git a/llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll 
b/llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll
index 018eb79b26fd..1175288cd09e 100644
--- a/llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll
+++ b/llvm/test/Transforms/ADCE/domtree-DoubleDeletion.ll
@@ -1,5 +1,5 @@
-; RUN: opt < %s -gvn -simplifycfg -adce | llvm-dis
-; RUN: opt < %s -gvn -simplifycfg -adce -verify-dom-info | llvm-dis
+; RUN: opt < %s -gvn -simplifycfg -simplifycfg-require-and-preserve-domtree=1 
-adce | llvm-dis
+; RUN: opt < %s -gvn -simplifycfg -simplifycfg-require-and-preserve-domtree=1 
-adce -verify-dom-info | llvm-dis
 
 ; This test makes sure that the DominatorTree properly handles
 ; deletion of edges that go to forward-unreachable regions.

diff  --git a/llvm/test/Transforms/JumpThreading/lvi-tristate.ll 
b/llvm/test/Transforms/JumpThreading/lvi-tristate.ll
index 94fd0e5049c4..ee0140035c3b 100644
--- a/llvm/test/Transforms/JumpThreading/lvi-tristate.ll
+++ b/llvm/test/Transforms/JumpThreading/lvi-tristate.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -jump-threading -

[llvm-branch-commits] [llvm] b7c463d - [SimplifyCFG] Teach FoldBranchToCommonDest() to preserve DomTree, part 2

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:23+03:00
New Revision: b7c463d7b8dda2c2b3e9a4db51f94dc94542ee68

URL: 
https://github.com/llvm/llvm-project/commit/b7c463d7b8dda2c2b3e9a4db51f94dc94542ee68
DIFF: 
https://github.com/llvm/llvm-project/commit/b7c463d7b8dda2c2b3e9a4db51f94dc94542ee68.diff

LOG: [SimplifyCFG] Teach FoldBranchToCommonDest() to preserve DomTree, part 2

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/branch-fold.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index f1e6c50130c8..d081908c49e9 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3121,6 +3121,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, 
DomTreeUpdater *DTU,
 assert(PBI_C->getType()->isIntegerTy(1));
 Instruction *MergedCond = nullptr;
 if (PBI->getSuccessor(0) == UniqueSucc) {
+  Updates.push_back(
+  {DominatorTree::Delete, PredBlock, PBI->getSuccessor(1)});
   // Create (PBI_Cond and PBI_C) or (!PBI_Cond and BI_Value)
   // PBI_C is true: PBI_Cond or (!PBI_Cond and BI_Value)
   //   is false: !PBI_Cond and BI_Value
@@ -3133,6 +3135,9 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, 
DomTreeUpdater *DTU,
 MergedCond = cast(Builder.CreateBinOp(
 Instruction::Or, PBI->getCondition(), MergedCond, "or.cond"));
 } else {
+  assert(PBI->getSuccessor(1) == UniqueSucc && "Unexpected branch");
+  Updates.push_back(
+  {DominatorTree::Delete, PredBlock, PBI->getSuccessor(0)});
   // Create (PBI_Cond and BI_Value) or (!PBI_Cond and PBI_C)
   // PBI_C is true: (PBI_Cond and BI_Value) or (!PBI_Cond)
   //   is false: PBI_Cond and BI_Value

diff  --git a/llvm/test/Transforms/SimplifyCFG/branch-fold.ll 
b/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
index 7097dea424e1..a4ac23bada70 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | 
FileCheck %s
 
 define void @test(i32* %P, i32* %Q, i1 %A, i1 %B) {
 ; CHECK: test



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 9f17dab - [SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:23+03:00
New Revision: 9f17dab1f48eed788d29e4c6f045e64b0679b3a9

URL: 
https://github.com/llvm/llvm-project/commit/9f17dab1f48eed788d29e4c6f045e64b0679b3a9
DIFF: 
https://github.com/llvm/llvm-project/commit/9f17dab1f48eed788d29e4c6f045e64b0679b3a9.diff

LOG: [SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/indirectbr.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d081908c49e9..1fd2956fac51 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6148,10 +6148,13 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst 
*IBI) {
   bool Changed = false;
 
   // Eliminate redundant destinations.
+  std::vector Updates;
   SmallPtrSet Succs;
   for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
 BasicBlock *Dest = IBI->getDestination(i);
 if (!Dest->hasAddressTaken() || !Succs.insert(Dest).second) {
+  if (!Dest->hasAddressTaken())
+Updates.push_back({DominatorTree::Delete, BB, Dest});
   Dest->removePredecessor(BB);
   IBI->removeDestination(i);
   --i;
@@ -6160,6 +6163,10 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst 
*IBI) {
 }
   }
 
+  if (DTU)
+DTU->applyUpdatesPermissive(Updates);
+  Updates.clear();
+
   if (IBI->getNumDestinations() == 0) {
 // If the indirectbr has no successors, change it to unreachable.
 new UnreachableInst(IBI->getContext(), IBI);

diff  --git a/llvm/test/Transforms/SimplifyCFG/indirectbr.ll 
b/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
index 67e23d2fe935..52ef6b77166c 100644
--- a/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
+++ b/llvm/test/Transforms/SimplifyCFG/indirectbr.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
 
 ; SimplifyCFG should eliminate redundant indirectbr edges.
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 0d2f219 - [SimplifyCFG] Teach SimplifyEqualityComparisonWithOnlyPredecessor() to preserve DomTree, part 3

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:23+03:00
New Revision: 0d2f219d4d0b4c61491508e6980055ecc241418c

URL: 
https://github.com/llvm/llvm-project/commit/0d2f219d4d0b4c61491508e6980055ecc241418c
DIFF: 
https://github.com/llvm/llvm-project/commit/0d2f219d4d0b4c61491508e6980055ecc241418c.diff

LOG: [SimplifyCFG] Teach SimplifyEqualityComparisonWithOnlyPredecessor() to 
preserve DomTree, part 3

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/switch_thread.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 1fd2956fac51..402b98efadad 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
@@ -934,13 +935,25 @@ bool 
SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
 LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
   << "Through successor TI: " << *TI);
 
+SmallMapVector NumPerSuccessorCases;
 for (SwitchInst::CaseIt i = SI->case_end(), e = SI->case_begin(); i != e;) 
{
   --i;
+  auto *Successor = i->getCaseSuccessor();
+  ++NumPerSuccessorCases[Successor];
   if (DeadCases.count(i->getCaseValue())) {
-i->getCaseSuccessor()->removePredecessor(TI->getParent());
+Successor->removePredecessor(PredDef);
 SI.removeCase(i);
+--NumPerSuccessorCases[Successor];
   }
 }
+
+std::vector Updates;
+for (const std::pair &I : NumPerSuccessorCases)
+  if (I.second == 0)
+Updates.push_back({DominatorTree::Delete, PredDef, I.first});
+if (DTU)
+  DTU->applyUpdatesPermissive(Updates);
+
 LLVM_DEBUG(dbgs() << "Leaving: " << *TI << "\n");
 return true;
   }

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_thread.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_thread.ll
index e38865699d2e..3688757253ad 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_thread.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_thread.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | 
FileCheck %s
 
 ; Test that we can thread a simple known condition through switch statements.
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] a815b6b - [SimplifyCFG] Teach eliminateDeadSwitchCases() to preserve DomTree, part 1

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:24+03:00
New Revision: a815b6b2b2cc483cfe9d2b520790322a39f8d37b

URL: 
https://github.com/llvm/llvm-project/commit/a815b6b2b2cc483cfe9d2b520790322a39f8d37b
DIFF: 
https://github.com/llvm/llvm-project/commit/a815b6b2b2cc483cfe9d2b520790322a39f8d37b.diff

LOG: [SimplifyCFG] Teach eliminateDeadSwitchCases() to preserve DomTree, part 1

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/switch-masked-bits.ll
llvm/test/Transforms/SimplifyCFG/switch-simplify-crash.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 402b98efadad..2ff576b17751 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4908,7 +4908,8 @@ bool SimplifyCFGOpt::TurnSwitchRangeIntoICmp(SwitchInst 
*SI,
 
 /// Compute masked bits for the condition of a switch
 /// and use it to remove dead cases.
-static bool eliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
+static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
+ AssumptionCache *AC,
  const DataLayout &DL) {
   Value *Cond = SI->getCondition();
   unsigned Bits = Cond->getType()->getIntegerBitWidth();
@@ -4922,11 +4923,15 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, 
AssumptionCache *AC,
 
   // Gather dead cases.
   SmallVector DeadCases;
+  SmallMapVector NumPerSuccessorCases;
   for (auto &Case : SI->cases()) {
+auto *Successor = Case.getCaseSuccessor();
+++NumPerSuccessorCases[Successor];
 const APInt &CaseVal = Case.getCaseValue()->getValue();
 if (Known.Zero.intersects(CaseVal) || !Known.One.isSubsetOf(CaseVal) ||
 (CaseVal.getMinSignedBits() > MaxSignificantBitsInCond)) {
   DeadCases.push_back(Case.getCaseValue());
+  --NumPerSuccessorCases[Successor];
   LLVM_DEBUG(dbgs() << "SimplifyCFG: switch case " << CaseVal
 << " is dead.\n");
 }
@@ -4961,6 +4966,13 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, 
AssumptionCache *AC,
 SIW.removeCase(CaseI);
   }
 
+  std::vector Updates;
+  for (const std::pair &I : NumPerSuccessorCases)
+if (I.second == 0)
+  Updates.push_back({DominatorTree::Delete, SI->getParent(), I.first});
+  if (DTU)
+DTU->applyUpdatesPermissive(Updates);
+
   return true;
 }
 
@@ -6132,7 +6144,7 @@ bool SimplifyCFGOpt::simplifySwitch(SwitchInst *SI, 
IRBuilder<> &Builder) {
 return requestResimplify();
 
   // Remove unreachable cases.
-  if (eliminateDeadSwitchCases(SI, Options.AC, DL))
+  if (eliminateDeadSwitchCases(SI, DTU, Options.AC, DL))
 return requestResimplify();
 
   if (switchToSelect(SI, Builder, DTU, DL, TTI))

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch-masked-bits.ll 
b/llvm/test/Transforms/SimplifyCFG/switch-masked-bits.ll
index 21cecc5c942b..1b8d6e70b7dd 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-masked-bits.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-masked-bits.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
 
 define i32 @test1(i32 %x) nounwind {
 ; CHECK-LABEL: @test1(

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch-simplify-crash.ll 
b/llvm/test/Transforms/SimplifyCFG/switch-simplify-crash.ll
index bbc0bd78da7c..755ad0a16338 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-simplify-crash.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-simplify-crash.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -disable-output
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 
-disable-output
 
 define void @NewExtractNames() {
 entry:



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 8866583 - [SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve DomTree, part 2

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:24+03:00
New Revision: 8866583953f1e9038b5ca4ed4c199e0476790e0c

URL: 
https://github.com/llvm/llvm-project/commit/8866583953f1e9038b5ca4ed4c199e0476790e0c
DIFF: 
https://github.com/llvm/llvm-project/commit/8866583953f1e9038b5ca4ed4c199e0476790e0c.diff

LOG: [SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve 
DomTree, part 2

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/PGOProfile/chr.ll
llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 2ff576b17751..bf61d34f7322 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1109,6 +1109,8 @@ bool 
SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
 
   std::vector Updates;
 
+  Updates.push_back({DominatorTree::Delete, Pred, BB});
+
   // Figure out which 'cases' to copy from SI to PSI.
   std::vector BBCases;
   BasicBlock *BBDefault = GetValueEqualityComparisonCases(TI, BBCases);

diff  --git a/llvm/test/Transforms/PGOProfile/chr.ll 
b/llvm/test/Transforms/PGOProfile/chr.ll
index 0390b87d..8a05a624209e 100644
--- a/llvm/test/Transforms/PGOProfile/chr.ll
+++ b/llvm/test/Transforms/PGOProfile/chr.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -chr -instcombine -simplifycfg -S -enable-new-pm=0 | FileCheck 
%s
+; RUN: opt < %s -chr -instcombine -simplifycfg 
-simplifycfg-require-and-preserve-domtree=1 -S -enable-new-pm=0 | FileCheck %s
 ; RUN: opt < %s 
-passes='require,function(chr,instcombine,simplify-cfg)' -S | 
FileCheck %s
 
 declare void @foo()

diff  --git a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll 
b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
index 2e356df75ca2..108fa3094add 100644
--- a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
+++ b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | not grep icmp
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S 
-hoist-common-insts=true | not grep icmp
 ; ModuleID = '/tmp/x.bc'
 target datalayout = 
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
 target triple = "i686-pc-linux-gnu"

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll
index 0df40349c1b3..e1095431f31f 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_switch_fold.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | 
FileCheck %s
 
 ; Test that a switch going to a switch on the same value can be merged.
 ; All three switches in this example can be merged into one big one.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 831636b - [SimplifyCFG] SUCCESS! Teach createUnreachableSwitchDefault() to preserve DomTree

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:25+03:00
New Revision: 831636b0e6321500fd7bf3f32e8663369152a956

URL: 
https://github.com/llvm/llvm-project/commit/831636b0e6321500fd7bf3f32e8663369152a956
DIFF: 
https://github.com/llvm/llvm-project/commit/831636b0e6321500fd7bf3f32e8663369152a956.diff

LOG: [SimplifyCFG] SUCCESS! Teach createUnreachableSwitchDefault() to preserve 
DomTree

This pretty much concludes patch series for updating SimplifyCFG
to preserve DomTree. All 318 dedicated `-simplifycfg` tests now pass
with `-simplifycfg-require-and-preserve-domtree=1`.

There are a few leftovers that apparently don't have good test coverage.
I do not yet know what gaps in test coverage will the wider-scale testing
reveal, but the default flip might be close.

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index f513db3783fb..53353cd5e923 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4783,15 +4783,29 @@ static bool 
CasesAreContiguous(SmallVectorImpl &Cases) {
   return true;
 }
 
-static void createUnreachableSwitchDefault(SwitchInst *Switch) {
+static void createUnreachableSwitchDefault(SwitchInst *Switch,
+   DomTreeUpdater *DTU) {
   LLVM_DEBUG(dbgs() << "SimplifyCFG: switch default is dead.\n");
+  auto *BB = Switch->getParent();
   BasicBlock *NewDefaultBlock =
- SplitBlockPredecessors(Switch->getDefaultDest(), Switch->getParent(), "");
+  SplitBlockPredecessors(Switch->getDefaultDest(), Switch->getParent(), "",
+ DTU ? &DTU->getDomTree() : nullptr);
+  auto *OrigDefaultBlock = Switch->getDefaultDest();
   Switch->setDefaultDest(&*NewDefaultBlock);
-  SplitBlock(&*NewDefaultBlock, &NewDefaultBlock->front());
+  if (DTU)
+DTU->applyUpdatesPermissive(
+{{DominatorTree::Delete, BB, OrigDefaultBlock},
+ {DominatorTree::Insert, BB, &*NewDefaultBlock}});
+  SplitBlock(&*NewDefaultBlock, &NewDefaultBlock->front(),
+ DTU ? &DTU->getDomTree() : nullptr);
+  SmallVector Updates;
+  for (auto *Successor : successors(NewDefaultBlock))
+Updates.push_back({DominatorTree::Delete, NewDefaultBlock, Successor});
   auto *NewTerminator = NewDefaultBlock->getTerminator();
   new UnreachableInst(Switch->getContext(), NewTerminator);
   EraseTerminatorAndDCECond(NewTerminator);
+  if (DTU)
+DTU->applyUpdatesPermissive(Updates);
 }
 
 /// Turn a switch with two reachable destinations into an integer range
@@ -4803,6 +4817,8 @@ bool SimplifyCFGOpt::TurnSwitchRangeIntoICmp(SwitchInst 
*SI,
   bool HasDefault =
   !isa(SI->getDefaultDest()->getFirstNonPHIOrDbg());
 
+  auto *BB = SI->getParent();
+
   // Partition the cases into two sets with 
diff erent destinations.
   BasicBlock *DestA = HasDefault ? SI->getDefaultDest() : nullptr;
   BasicBlock *DestB = nullptr;
@@ -4906,11 +4922,17 @@ bool SimplifyCFGOpt::TurnSwitchRangeIntoICmp(SwitchInst 
*SI,
   // Clean up the default block - it may have phis or other instructions before
   // the unreachable terminator.
   if (!HasDefault)
-createUnreachableSwitchDefault(SI);
+createUnreachableSwitchDefault(SI, DTU);
+
+  auto *UnreachableDefault = SI->getDefaultDest();
 
   // Drop the switch.
   SI->eraseFromParent();
 
+  if (!HasDefault && DTU)
+DTU->applyUpdatesPermissive(
+{{DominatorTree::Delete, BB, UnreachableDefault}});
+
   return true;
 }
 
@@ -4957,7 +4979,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, 
DomTreeUpdater *DTU,
   if (HasDefault && DeadCases.empty() &&
   NumUnknownBits < 64 /* avoid overflow */ &&
   SI->getNumCases() == (1ULL << NumUnknownBits)) {
-createUnreachableSwitchDefault(SI);
+createUnreachableSwitchDefault(SI, /*DTU=*/nullptr);
 return true;
   }
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll 
b/llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll
index d99e84b6b940..7125575b2f33 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt %s -simplifycfg -S | FileCheck %s
+; RUN: opt %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | 
FileCheck %s
 
 declare i32 @f(i32)
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] e1440d4 - [SimplifyCFG] Teach tryToSimplifyUncondBranchWithICmpInIt() to preserve DomTree

2020-12-31 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-01T03:25:25+03:00
New Revision: e1440d43bca5438544a12bebe82a3cd1a37157f1

URL: 
https://github.com/llvm/llvm-project/commit/e1440d43bca5438544a12bebe82a3cd1a37157f1
DIFF: 
https://github.com/llvm/llvm-project/commit/e1440d43bca5438544a12bebe82a3cd1a37157f1.diff

LOG: [SimplifyCFG] Teach tryToSimplifyUncondBranchWithICmpInIt() to preserve 
DomTree

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
llvm/test/Transforms/SimplifyCFG/switch_create.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index bf61d34f7322..f513db3783fb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4052,6 +4052,8 @@ bool 
SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpInIt(
   ICI->replaceAllUsesWith(DefaultCst);
   ICI->eraseFromParent();
 
+  SmallVector Updates;
+
   // Okay, the switch goes to this block on a default value.  Add an edge from
   // the switch to the merge point on the compared value.
   BasicBlock *NewBB =
@@ -4065,13 +4067,17 @@ bool 
SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpInIt(
   SIW.setSuccessorWeight(0, *NewW);
 }
 SIW.addCase(Cst, NewBB, NewW);
+Updates.push_back({DominatorTree::Insert, Pred, NewBB});
   }
 
   // NewBB branches to the phi block, add the uncond branch and the phi entry.
   Builder.SetInsertPoint(NewBB);
   Builder.SetCurrentDebugLocation(SI->getDebugLoc());
   Builder.CreateBr(SuccBlock);
+  Updates.push_back({DominatorTree::Insert, NewBB, SuccBlock});
   PHIUse->addIncoming(NewCst, NewBB);
+  if (DTU)
+DTU->applyUpdatesPermissive(Updates);
   return true;
 }
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll 
b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index 66a34bab3e5b..078d0aa2f1de 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
+; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -o - < 
%s | FileCheck %s
 
 declare void @helper(i32)
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
index dc07eb20568d..cdc334e474b6 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
 target datalayout="p:40:64:64:32"
 
 declare void @foo1()

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_create.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
index 10689a03c398..a4c84a66cafb 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_create.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
-; RUN: opt -S -data-layout="p:32:32-p1:16:16" -simplifycfg < %s | FileCheck 
-check-prefix=CHECK -check-prefix=DL %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
+; RUN: opt -S -data-layout="p:32:32-p1:16:16" -simplifycfg 
-simplifycfg-require-and-preserve-domtree=1 < %s | FileCheck 
-check-prefix=CHECK -check-prefix=DL %s
 
 declare void @foo1()
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 0d21e66 - [IRSim] Letting call instructions be legal for similarity identification.

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T20:52:45-06:00
New Revision: 0d21e66014fc5cac1302a148e65d5ad6a41af37b

URL: 
https://github.com/llvm/llvm-project/commit/0d21e66014fc5cac1302a148e65d5ad6a41af37b
DIFF: 
https://github.com/llvm/llvm-project/commit/0d21e66014fc5cac1302a148e65d5ad6a41af37b.diff

LOG: [IRSim] Letting call instructions be legal for similarity identification.

Here we let non-intrinsic calls be considered legal and valid for
similarity only if the call is not indirect, and has a name.

For two calls to be considered similar, they must have the same name,
the same function types, and the same set of parameters, including tail
calls and calling conventions.

Tests are found in unittests/Analysis/IRSimilarityIdentifierTest.cpp.

Reviewers: jroelofs, paquette

Differential Revision: https://reviews.llvm.org/D87312

Added: 


Modified: 
llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
llvm/lib/Analysis/IRSimilarityIdentifier.cpp
llvm/test/Transforms/IROutliner/illegal-calls.ll
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp

Removed: 




diff  --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h 
b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
index a3004ca0dc59..9e97541e542b 100644
--- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
+++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
@@ -183,6 +183,12 @@ struct IRInstructionData : ilist_node {
   llvm::hash_value(ID.Inst->getType()),
   llvm::hash_value(ID.getPredicate()),
   llvm::hash_combine_range(OperTypes.begin(), OperTypes.end()));
+else if (CallInst *CI = dyn_cast(ID.Inst))
+  return llvm::hash_combine(
+  llvm::hash_value(ID.Inst->getOpcode()),
+  llvm::hash_value(ID.Inst->getType()),
+  llvm::hash_value(CI->getCalledFunction()->getName().str()),
+  llvm::hash_combine_range(OperTypes.begin(), OperTypes.end()));
 return llvm::hash_combine(
 llvm::hash_value(ID.Inst->getOpcode()),
 llvm::hash_value(ID.Inst->getType()),
@@ -398,8 +404,14 @@ struct IRInstructionMapper {
 InstrType visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) { return Invisible; 
}
 // TODO: Handle specific intrinsics.
 InstrType visitIntrinsicInst(IntrinsicInst &II) { return Illegal; }
-// TODO: Handle CallInsts.
-InstrType visitCallInst(CallInst &CI) { return Illegal; }
+// We only allow call instructions where the function has a name and
+// is not an indirect call.
+InstrType visitCallInst(CallInst &CI) {
+  Function *F = CI.getCalledFunction();
+  if (!F || CI.isIndirectCall() || !F->hasName())
+return Illegal;
+  return Legal;
+}
 // TODO: We do not current handle similarity that changes the control flow.
 InstrType visitInvokeInst(InvokeInst &II) { return Illegal; }
 // TODO: We do not current handle similarity that changes the control flow.

diff  --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp 
b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
index c276e3f28d73..60b4f427e189 100644
--- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
+++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
@@ -75,6 +75,12 @@ CmpInst::Predicate IRInstructionData::getPredicate() const {
   return cast(Inst)->getPredicate();
 }
 
+static StringRef getCalledFunctionName(CallInst &CI) {
+  assert(CI.getCalledFunction() != nullptr && "Called Function is nullptr?");
+
+  return CI.getCalledFunction()->getName();
+}
+
 bool IRSimilarity::isClose(const IRInstructionData &A,
const IRInstructionData &B) {
 
@@ -129,6 +135,16 @@ bool IRSimilarity::isClose(const IRInstructionData &A,
});
   }
 
+  // If the instructions are functions, we make sure that the function name is
+  // the same.  We already know that the types are since is isSameOperationAs 
is
+  // true.
+  if (isa(A.Inst) && isa(B.Inst)) {
+CallInst *CIA = cast(A.Inst);
+CallInst *CIB = cast(B.Inst);
+if (getCalledFunctionName(*CIA).compare(getCalledFunctionName(*CIB)) != 0)
+  return false;
+  }
+
   return true;
 }
 

diff  --git a/llvm/test/Transforms/IROutliner/illegal-calls.ll 
b/llvm/test/Transforms/IROutliner/illegal-calls.ll
index 99c8f6fa838d..18d37c2f4dc0 100644
--- a/llvm/test/Transforms/IROutliner/illegal-calls.ll
+++ b/llvm/test/Transforms/IROutliner/illegal-calls.ll
@@ -13,7 +13,9 @@ define void @outline_constants1() {
 ; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[C:%.*]] = alloca i32, align 4
-; CHECK-NEXT:call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* 
[[C]])
+; CHECK-NEXT:store i32 2, i32* [[A]], align 4
+; CHECK-NEXT:store i32 3, i32* [[B]], align 4
+; CHECK-NEXT:store i32 4, i32* [[C]], align 4
 ; CHECK-NEXT:call void @f1(i32* [[A]], i32* [[B]])
 ; CHECK-NEXT

[llvm-branch-commits] [llvm] 57a4691 - [IRSim][IROutliner] Allowing call instructions to be outlined.

2020-12-31 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2020-12-31T23:01:29-06:00
New Revision: 57a46914f5c1efbdc130dc7a06f8d5b45d606f8d

URL: 
https://github.com/llvm/llvm-project/commit/57a46914f5c1efbdc130dc7a06f8d5b45d606f8d
DIFF: 
https://github.com/llvm/llvm-project/commit/57a46914f5c1efbdc130dc7a06f8d5b45d606f8d.diff

LOG: [IRSim][IROutliner] Allowing call instructions to be outlined.

We add an extra check to make sure that we do not outline calls to
indirect functions, but outline whatever the IRSimilarityIdentifier
finds with respect to calls.

Tests:
Removing test/Transforms/IROutliner/illegal-calls.ll
Adding test/Transforms/IROutliner/outlining-calls.ll
Adding test/Transforms/IROutliner/illegal-indirect-calls.ll

Excluding DebugInfo this is the last patch for the initial
implementation of the IROutliner!

Reviewers: jroelofs, paquette

Differential Revision: https://reviews.llvm.org/D87314

Added: 
llvm/test/Transforms/IROutliner/illegal-indirect-calls.ll
llvm/test/Transforms/IROutliner/outlining-calls.ll

Modified: 
llvm/include/llvm/Transforms/IPO/IROutliner.h

Removed: 
llvm/test/Transforms/IROutliner/illegal-calls.ll



diff  --git a/llvm/include/llvm/Transforms/IPO/IROutliner.h 
b/llvm/include/llvm/Transforms/IPO/IROutliner.h
index fef02b18b7c3..0346803e9ad7 100644
--- a/llvm/include/llvm/Transforms/IPO/IROutliner.h
+++ b/llvm/include/llvm/Transforms/IPO/IROutliner.h
@@ -321,9 +321,14 @@ class IROutliner {
 // TODO: Handle specific intrinsics individually from those that can be
 // handled.
 bool IntrinsicInst(IntrinsicInst &II) { return false; }
-// TODO: Handle CallInsts, there will need to be handling for special kinds
-// of calls, as well as calls to intrinsics.
-bool visitCallInst(CallInst &CI) { return false; }
+// We only handle CallInsts that are not indirect, since we cannot 
guarantee
+// that they have a name in these cases.
+bool visitCallInst(CallInst &CI) {
+  Function *F = CI.getCalledFunction();
+  if (!F || CI.isIndirectCall() || !F->hasName())
+return false;
+  return true;
+}
 // TODO: Handle FreezeInsts.  Since a frozen value could be frozen inside
 // the outlined region, and then returned as an output, this will have to 
be
 // handled 
diff erently.

diff  --git a/llvm/test/Transforms/IROutliner/illegal-calls.ll 
b/llvm/test/Transforms/IROutliner/illegal-indirect-calls.ll
similarity index 60%
rename from llvm/test/Transforms/IROutliner/illegal-calls.ll
rename to llvm/test/Transforms/IROutliner/illegal-indirect-calls.ll
index 18d37c2f4dc0..513fa60dc625 100644
--- a/llvm/test/Transforms/IROutliner/illegal-calls.ll
+++ b/llvm/test/Transforms/IROutliner/illegal-indirect-calls.ll
@@ -1,22 +1,21 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -verify -iroutliner -ir-outlining-no-cost < %s | FileCheck %s
 
-; This test checks that we do not outline calls.  Special calls, such as
-; indirect or nameless calls require extra handling to ensure that there
-; are no inconsistencies when outlining and consolidating regions.
+; This test checks that we do not outline indirect calls.  We cannot guarantee
+; that we have the same name in these cases, so two indirect calls cannot
+; be considered similar.
 
 declare void @f1(i32*, i32*);
+declare void @f2(i32*, i32*);
 
-define void @outline_constants1() {
-; CHECK-LABEL: @outline_constants1(
+define void @function1(void()* %func) {
+; CHECK-LABEL: @function1(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[C:%.*]] = alloca i32, align 4
-; CHECK-NEXT:store i32 2, i32* [[A]], align 4
-; CHECK-NEXT:store i32 3, i32* [[B]], align 4
-; CHECK-NEXT:store i32 4, i32* [[C]], align 4
-; CHECK-NEXT:call void @f1(i32* [[A]], i32* [[B]])
+; CHECK-NEXT:call void @outlined_ir_func_1(i32* [[A]], i32* [[B]], i32* 
[[C]])
+; CHECK-NEXT:call void [[FUNC:%.*]]()
 ; CHECK-NEXT:call void @outlined_ir_func_0(i32* [[A]], i32* [[B]], i32* 
[[C]])
 ; CHECK-NEXT:ret void
 ;
@@ -27,23 +26,21 @@ entry:
   store i32 2, i32* %a, align 4
   store i32 3, i32* %b, align 4
   store i32 4, i32* %c, align 4
-  call void @f1(i32* %a, i32* %b)
+  call void %func()
   %al = load i32, i32* %a
   %bl = load i32, i32* %b
   %cl = load i32, i32* %c
   ret void
 }
 
-define void @outline_constants2() {
-; CHECK-LABEL: @outline_constants2(
+define void @function2(void()* %func) {
+; CHECK-LABEL: @function2(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[B:%.*]] = alloca i32, align 4
 ; CHECK-NEXT:[[C:%.*]] = alloca i32, align 4
-; CHECK-NEXT:store i32 2, i32* [[A]], align 4
-; CHECK-NEXT:store i32 3, i32* [[B]], align 4
-; CHECK-NEXT:store i32 4, i32* [[C]], align 4
-; CHECK-NEXT:call void @f1(i32* [[A]

[llvm-branch-commits] [clang] 89b0972 - [Sema] Fix deleted function problem in implicitly movable test

2020-12-31 Thread Yang Fan via llvm-branch-commits

Author: Yang Fan
Date: 2021-01-01T15:47:49+08:00
New Revision: 89b0972aa2f58f927633c63570b36550a17f4e63

URL: 
https://github.com/llvm/llvm-project/commit/89b0972aa2f58f927633c63570b36550a17f4e63
DIFF: 
https://github.com/llvm/llvm-project/commit/89b0972aa2f58f927633c63570b36550a17f4e63.diff

LOG: [Sema] Fix deleted function problem in implicitly movable test

In implicitly movable test, a two-stage overload resolution is performed.
If the first overload resolution selects a deleted function, Clang directly
performs the second overload resolution, without checking whether the
deleted function matches the additional criteria.

This patch fixes the above problem.

Reviewed By: Quuxplusone

Differential Revision: https://reviews.llvm.org/D92936

Added: 
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Modified: 
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 6d2e6094e79c..4a965c60c74e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4119,7 +4119,9 @@ static void TryConstructorInitialization(Sema &S,
   InitializationSequence::FK_ListConstructorOverloadFailed 
:
   InitializationSequence::FK_ConstructorOverloadFailed,
 Result);
-return;
+
+if (Result != OR_Deleted)
+  return;
   }
 
   bool HadMultipleCandidates = (CandidateSet.size() > 1);
@@ -4140,31 +4142,45 @@ static void TryConstructorInitialization(Sema &S,
 return;
   }
 
-  // C++11 [dcl.init]p6:
-  //   If a program calls for the default initialization of an object
-  //   of a const-qualified type T, T shall be a class type with a
-  //   user-provided default constructor.
-  // C++ core issue 253 proposal:
-  //   If the implicit default constructor initializes all subobjects, no
-  //   initializer should be required.
-  // The 253 proposal is for example needed to process libstdc++ headers in 
5.x.
   CXXConstructorDecl *CtorDecl = cast(Best->Function);
-  if (Kind.getKind() == InitializationKind::IK_Default &&
-  Entity.getType().isConstQualified()) {
-if (!CtorDecl->getParent()->allowConstDefaultInit()) {
-  if (!maybeRecoverWithZeroInitialization(S, Sequence, Entity))
-Sequence.SetFailed(InitializationSequence::FK_DefaultInitOfConst);
+  if (Result != OR_Deleted) { // TODO: Support for more than one failure.
+// C++11 [dcl.init]p6:
+//   If a program calls for the default initialization of an object
+//   of a const-qualified type T, T shall be a class type with a
+//   user-provided default constructor.
+// C++ core issue 253 proposal:
+//   If the implicit default constructor initializes all subobjects, no
+//   initializer should be required.
+// The 253 proposal is for example needed to process libstdc++ headers
+// in 5.x.
+if (Kind.getKind() == InitializationKind::IK_Default &&
+Entity.getType().isConstQualified()) {
+  if (!CtorDecl->getParent()->allowConstDefaultInit()) {
+if (!maybeRecoverWithZeroInitialization(S, Sequence, Entity))
+  Sequence.SetFailed(InitializationSequence::FK_DefaultInitOfConst);
+return;
+  }
+}
+
+// C++11 [over.match.list]p1:
+//   In copy-list-initialization, if an explicit constructor is chosen, the
+//   initializer is ill-formed.
+if (IsListInit && !Kind.AllowExplicit() && CtorDecl->isExplicit()) {
+  Sequence.SetFailed(InitializationSequence::FK_ExplicitConstructor);
   return;
 }
   }
 
-  // C++11 [over.match.list]p1:
-  //   In copy-list-initialization, if an explicit constructor is chosen, the
-  //   initializer is ill-formed.
-  if (IsListInit && !Kind.AllowExplicit() && CtorDecl->isExplicit()) {
-Sequence.SetFailed(InitializationSequence::FK_ExplicitConstructor);
+  // [class.copy.elision]p3:
+  // In some copy-initialization contexts, a two-stage overload resolution
+  // is performed.
+  // If the first overload resolution selects a deleted function, we also
+  // need the initialization sequence to decide whether to perform the second
+  // overload resolution.
+  // For deleted functions in other contexts, there is no need to get the
+  // initialization sequence.
+  if (Result == OR_Deleted && Kind.getKind() != InitializationKind::IK_Copy)
 return;
-  }
 
   // Add the constructor initialization step. Any cv-qualification conversion 
is
   // subsumed by the initialization.
@@ -5260,7 +5276,16 @@ static void TryUserDefinedConversion(Sema &S,
 Sequence.SetOverloadFailure(
 
InitializationSequence::FK_UserConversionOverloadFailed,
 Result);
-return;
+
+// [class.copy.elision]p3:
+// In some copy-initialization contexts, a two-stage overload resolution
+// is perfo