[llvm] r352739 - Default lowering for experimental.widenable.condition

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 11 00:26:38 PST 2019


FYi, some files slipped in here using the old header. I've fixed them, but
something to keep an eye on with other patches.

On Thu, Jan 31, 2019 at 1:10 AM Max Kazantsev via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: mkazantsev
> Date: Thu Jan 31 01:10:17 2019
> New Revision: 352739
>
> URL: http://llvm.org/viewvc/llvm-project?rev=352739&view=rev
> Log:
> Default lowering for experimental.widenable.condition
>
> Introduces a pass that provides default lowering strategy for the
> `experimental.widenable.condition` intrinsic, replacing all its uses with
> `i1 true`.
>
> Differential Revision: https://reviews.llvm.org/D56096
> Reviewed By: reames
>
> Added:
>     llvm/trunk/include/llvm/Transforms/Scalar/LowerWidenableCondition.h
>     llvm/trunk/lib/Transforms/Scalar/LowerWidenableCondition.cpp
>     llvm/trunk/test/Transforms/LowerWidenableCondition/
>     llvm/trunk/test/Transforms/LowerWidenableCondition/basic.ll
> Modified:
>     llvm/trunk/include/llvm/InitializePasses.h
>     llvm/trunk/include/llvm/Transforms/Scalar.h
>     llvm/trunk/lib/Passes/PassBuilder.cpp
>     llvm/trunk/lib/Passes/PassRegistry.def
>     llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt
>     llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
>
> Modified: llvm/trunk/include/llvm/InitializePasses.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/InitializePasses.h (original)
> +++ llvm/trunk/include/llvm/InitializePasses.h Thu Jan 31 01:10:17 2019
> @@ -240,6 +240,7 @@ void initializeLowerAtomicLegacyPassPass
>  void initializeLowerEmuTLSPass(PassRegistry&);
>  void initializeLowerExpectIntrinsicPass(PassRegistry&);
>  void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&);
> +void initializeLowerWidenableConditionLegacyPassPass(PassRegistry&);
>  void initializeLowerIntrinsicsPass(PassRegistry&);
>  void initializeLowerInvokeLegacyPassPass(PassRegistry&);
>  void initializeLowerSwitchPass(PassRegistry&);
>
> Modified: llvm/trunk/include/llvm/Transforms/Scalar.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar.h?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Scalar.h (original)
> +++ llvm/trunk/include/llvm/Transforms/Scalar.h Thu Jan 31 01:10:17 2019
> @@ -359,6 +359,12 @@ Pass *createLowerGuardIntrinsicPass();
>
>
>  //===----------------------------------------------------------------------===//
>  //
> +// LowerWidenableCondition - Lower widenable condition to i1 true.
> +//
> +Pass *createLowerWidenableConditionPass();
> +
>
> +//===----------------------------------------------------------------------===//
> +//
>  // MergeICmps - Merge integer comparison chains into a memcmp
>  //
>  Pass *createMergeICmpsPass();
>
> Added: llvm/trunk/include/llvm/Transforms/Scalar/LowerWidenableCondition.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/LowerWidenableCondition.h?rev=352739&view=auto
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Scalar/LowerWidenableCondition.h
> (added)
> +++ llvm/trunk/include/llvm/Transforms/Scalar/LowerWidenableCondition.h
> Thu Jan 31 01:10:17 2019
> @@ -0,0 +1,27 @@
> +//===--- LowerWidenableCondition.h - Lower the guard intrinsic
> ---------------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +//
> +// This pass lowers the llvm.widenable.condition intrinsic to default
> value
> +// which is i1 true.
> +//
>
> +//===----------------------------------------------------------------------===//
> +#ifndef LLVM_TRANSFORMS_SCALAR_LOWERWIDENABLECONDITION_H
> +#define LLVM_TRANSFORMS_SCALAR_LOWERWIDENABLECONDITION_H
> +
> +#include "llvm/IR/PassManager.h"
> +
> +namespace llvm {
> +
> +struct LowerWidenableConditionPass :
> PassInfoMixin<LowerWidenableConditionPass> {
> +  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
> +};
> +
> +}
> +
> +#endif //LLVM_TRANSFORMS_SCALAR_LOWERWIDENABLECONDITION_H
>
> Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
> +++ llvm/trunk/lib/Passes/PassBuilder.cpp Thu Jan 31 01:10:17 2019
> @@ -133,6 +133,7 @@
>  #include "llvm/Transforms/Scalar/LowerAtomic.h"
>  #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
>  #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
> +#include "llvm/Transforms/Scalar/LowerWidenableCondition.h"
>  #include "llvm/Transforms/Scalar/MakeGuardsExplicit.h"
>  #include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
>  #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
>
> Modified: llvm/trunk/lib/Passes/PassRegistry.def
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassRegistry.def (original)
> +++ llvm/trunk/lib/Passes/PassRegistry.def Thu Jan 31 01:10:17 2019
> @@ -177,6 +177,7 @@ FUNCTION_PASS("libcalls-shrinkwrap", Lib
>  FUNCTION_PASS("loweratomic", LowerAtomicPass())
>  FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
>  FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
> +FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass())
>  FUNCTION_PASS("guard-widening", GuardWideningPass())
>  FUNCTION_PASS("gvn", GVN())
>  FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass())
>
> Modified: llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt (original)
> +++ llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt Thu Jan 31 01:10:17
> 2019
> @@ -45,6 +45,7 @@ add_llvm_library(LLVMScalarOpts
>    LowerAtomic.cpp
>    LowerExpectIntrinsic.cpp
>    LowerGuardIntrinsic.cpp
> +  LowerWidenableCondition.cpp
>    MakeGuardsExplicit.cpp
>    MemCpyOptimizer.cpp
>    MergeICmps.cpp
>
> Added: llvm/trunk/lib/Transforms/Scalar/LowerWidenableCondition.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LowerWidenableCondition.cpp?rev=352739&view=auto
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LowerWidenableCondition.cpp (added)
> +++ llvm/trunk/lib/Transforms/Scalar/LowerWidenableCondition.cpp Thu Jan
> 31 01:10:17 2019
> @@ -0,0 +1,86 @@
> +//===- LowerWidenableCondition.cpp - Lower the guard intrinsic
> ---------------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +//
> +// This pass lowers the llvm.widenable.condition intrinsic to default
> value
> +// which is i1 true.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +#include "llvm/Transforms/Scalar/LowerWidenableCondition.h"
> +#include "llvm/ADT/SmallVector.h"
> +#include "llvm/Analysis/GuardUtils.h"
> +#include "llvm/IR/BasicBlock.h"
> +#include "llvm/IR/Function.h"
> +#include "llvm/IR/InstIterator.h"
> +#include "llvm/IR/Instructions.h"
> +#include "llvm/IR/Intrinsics.h"
> +#include "llvm/IR/Module.h"
> +#include "llvm/IR/PatternMatch.h"
> +#include "llvm/Pass.h"
> +#include "llvm/Transforms/Scalar.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
> +
> +using namespace llvm;
> +
> +namespace {
> +struct LowerWidenableConditionLegacyPass : public FunctionPass {
> +  static char ID;
> +  LowerWidenableConditionLegacyPass() : FunctionPass(ID) {
> +    initializeLowerWidenableConditionLegacyPassPass(
> +        *PassRegistry::getPassRegistry());
> +  }
> +
> +  bool runOnFunction(Function &F) override;
> +};
> +}
> +
> +static bool lowerWidenableCondition(Function &F) {
> +  // Check if we can cheaply rule out the possibility of not having any
> work to
> +  // do.
> +  auto *WCDecl = F.getParent()->getFunction(
> +      Intrinsic::getName(Intrinsic::experimental_widenable_condition));
> +  if (!WCDecl || WCDecl->use_empty())
> +    return false;
> +
> +  using namespace llvm::PatternMatch;
> +  SmallVector<CallInst *, 8> ToLower;
> +  for (auto &I : instructions(F))
> +    if (match(&I,
> m_Intrinsic<Intrinsic::experimental_widenable_condition>()))
> +      ToLower.push_back(cast<CallInst>(&I));
> +
> +  if (ToLower.empty())
> +    return false;
> +
> +  for (auto *CI : ToLower) {
> +    CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
> +    CI->eraseFromParent();
> +  }
> +  return true;
> +}
> +
> +bool LowerWidenableConditionLegacyPass::runOnFunction(Function &F) {
> +  return lowerWidenableCondition(F);
> +}
> +
> +char LowerWidenableConditionLegacyPass::ID = 0;
> +INITIALIZE_PASS(LowerWidenableConditionLegacyPass,
> "lower-widenable-condition",
> +                "Lower the widenable condition to default true value",
> false,
> +                false)
> +
> +Pass *llvm::createLowerWidenableConditionPass() {
> +  return new LowerWidenableConditionLegacyPass();
> +}
> +
> +PreservedAnalyses LowerWidenableConditionPass::run(Function &F,
> +                                               FunctionAnalysisManager
> &AM) {
> +  if (lowerWidenableCondition(F))
> +    return PreservedAnalyses::none();
> +
> +  return PreservedAnalyses::all();
> +}
>
> Modified: llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Scalar.cpp?rev=352739&r1=352738&r2=352739&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/Scalar.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/Scalar.cpp Thu Jan 31 01:10:17 2019
> @@ -80,6 +80,7 @@ void llvm::initializeScalarOpts(PassRegi
>    initializeLowerAtomicLegacyPassPass(Registry);
>    initializeLowerExpectIntrinsicPass(Registry);
>    initializeLowerGuardIntrinsicLegacyPassPass(Registry);
> +  initializeLowerWidenableConditionLegacyPassPass(Registry);
>    initializeMemCpyOptLegacyPassPass(Registry);
>    initializeMergeICmpsPass(Registry);
>    initializeMergedLoadStoreMotionLegacyPassPass(Registry);
>
> Added: llvm/trunk/test/Transforms/LowerWidenableCondition/basic.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LowerWidenableCondition/basic.ll?rev=352739&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/LowerWidenableCondition/basic.ll (added)
> +++ llvm/trunk/test/Transforms/LowerWidenableCondition/basic.ll Thu Jan 31
> 01:10:17 2019
> @@ -0,0 +1,44 @@
> +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
> +; RUN: opt -S -lower-widenable-condition < %s        | FileCheck %s
> +; RUN: opt -S -passes=lower-widenable-condition < %s | FileCheck %s
> +
> +; Basic test case: make sure that all widenable conditions turn into i1
> true.
> +define void @f_0(i1 %cond_0, i1 %cond_1) {
> +; CHECK-LABEL: @f_0(
> +; CHECK-NEXT:  entry:
> +; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[COND_0:%.*]],
> true
> +; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED:%.*]],
> label [[DEOPT:%.*]]
> +; CHECK:       deopt:
> +; CHECK-NEXT:    unreachable
> +; CHECK:       guarded:
> +; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND4:%.*]] = and i1 [[COND_1:%.*]],
> true
> +; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND4]], label [[GUARDED1:%.*]],
> label [[DEOPT2:%.*]]
> +; CHECK:       deopt2:
> +; CHECK-NEXT:    unreachable
> +; CHECK:       guarded1:
> +; CHECK-NEXT:    ret void
> +;
> +entry:
> +  %widenable_cond = call i1 @llvm.experimental.widenable.condition()
> +  %exiplicit_guard_cond = and i1 %cond_0, %widenable_cond
> +  br i1 %exiplicit_guard_cond, label %guarded, label %deopt
> +
> +deopt:                                            ; preds = %entry
> +  unreachable
> +
> +guarded:                                          ; preds = %entry
> +  %widenable_cond3 = call i1 @llvm.experimental.widenable.condition()
> +  %exiplicit_guard_cond4 = and i1 %cond_1, %widenable_cond3
> +  br i1 %exiplicit_guard_cond4, label %guarded1, label %deopt2
> +
> +deopt2:                                           ; preds = %guarded
> +  unreachable
> +
> +guarded1:                                         ; preds = %guarded
> +  ret void
> +}
> +
> +; Function Attrs: inaccessiblememonly nounwind
> +declare i1 @llvm.experimental.widenable.condition() #0
> +
> +attributes #0 = { inaccessiblememonly nounwind }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190211/ddfe6113/attachment.html>


More information about the llvm-commits mailing list