diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -341,6 +341,10 @@ PreservedAnalyses JumpThreadingPass::run(Function &F, FunctionAnalysisManager &AM) { + auto &TTI = AM.getResult(F); + // Jump Threading has no sense for the targets with divergent CF + if (TTI.hasBranchDivergence()) + return PreservedAnalyses::all(); auto &TLI = AM.getResult(F); auto &DT = AM.getResult(F); auto &LVI = AM.getResult(F); diff --git a/llvm/test/Transforms/JumpThreading/divergent-target-test.ll b/llvm/test/Transforms/JumpThreading/divergent-target-test.ll --- a/llvm/test/Transforms/JumpThreading/divergent-target-test.ll +++ b/llvm/test/Transforms/JumpThreading/divergent-target-test.ll @@ -1,6 +1,8 @@ ; REQUIRES: amdgpu-registered-target && x86-registered-target ; RUN: opt < %s -mtriple=amdgcn -jump-threading -S | FileCheck %s -check-prefixes=CHECK,DIVERGENT +; RUN: opt < %s -mtriple=amdgcn -passes=jump-threading -S | FileCheck %s -check-prefixes=CHECK,DIVERGENT ; RUN: opt < %s -mtriple=x86_64 -jump-threading -S | FileCheck %s -check-prefixes=CHECK,UNIFORM +; RUN: opt < %s -mtriple=x86_64 -passes=jump-threading -S | FileCheck %s -check-prefixes=CHECK,UNIFORM ; Here we assure that for the target with no branch divergence usual Jump Threading optimization performed ; For target with branch divergence - no optimization, so the IR is unchanged.