[llvm] 8293f74 - Further cleanup manipulation of widenable branches [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 11:42:31 PST 2019


Thank for drawing my attention.  3f8a2af8f should fix this, I hope.  
Will watch the bot and make sure.

Philip

On 11/22/19 10:47 AM, Kostya Serebryany wrote:
> Hi Philip,
>
> The ubsan bootstrap bot crashes in the new code:
> FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang++ 
> -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support 
> -I/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support 
> -I/usr/include/libxml2 -Iinclude 
> -I/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include 
> -fsanitize=undefined -w -fPIC -fvisibility-inlines-hidden 
> -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -pedantic -Wno-long-long 
> -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess 
> -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
> -Wstring-conversion -fno-omit-frame-pointer -gline-tables-only 
> -fsanitize=undefined -fno-sanitize=vptr,function 
> -fno-sanitize-recover=all 
> -fsanitize-blacklist=/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/sanitizers/ubsan_blacklist.txt 
> -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -UNDEBUG 
> -std=c++14 -fno-exceptions -fno-rtti -MD -MT 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o -MF 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o.d -o 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o -c 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp 
> clang-10: 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Casting.h:264: 
> typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = 
> llvm::Instruction; Y = llvm::Value; typename llvm::cast_retty<X, 
> Y*>::ret_type = llvm::Instruction*]: Assertion `isa<X>(Val) && 
> "cast<Ty>() argument of incompatible type!"' failed. Stack dump: 0. 
> Program arguments: 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10 
> -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free 
> -main-file-name Signals.cpp -mrelocation-model pic -pic-level 2 
> -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose 
> -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu 
> x86-64 -dwarf-column-info -debug-info-kind=line-tables-only 
> -dwarf-version=4 -debugger-tuning=gdb -ffunction-sections 
> -fdata-sections -resource-dir 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/lib/clang/10.0.0 
> -dependency-file 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o.d -MT 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o -sys-header-deps 
> -D GTEST_HAS_RTTI=0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS 
> -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/Support -I 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support 
> -I /usr/include/libxml2 -I include -I 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include 
> -U NDEBUG -internal-isystem 
> /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 
> -internal-isystem 
> /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 
> -internal-isystem 
> /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 
> -internal-isystem 
> /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward 
> -internal-isystem /usr/local/include -internal-isystem 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/lib/clang/10.0.0/include 
> -internal-externc-isystem /usr/include/x86_64-linux-gnu 
> -internal-externc-isystem /include -internal-externc-isystem 
> /usr/include -O3 -Werror=date-time -Werror=unguarded-availability-new 
> -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -Wno-long-long -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type 
> -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion 
> -pedantic -w -std=c++14 -fdeprecated-macro -fdebug-compilation-dir 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan 
> -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden 
> -fsanitize=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound 
> -fsanitize-blacklist=/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/sanitizers/ubsan_blacklist.txt 
> -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc 
> -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops 
> -vectorize-slp -faddrsig -o 
> lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o -x c++ 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp 
> 1. <eof> parser at end of file 2. Per-module optimization passes 3. 
> Running pass 'CallGraph Pass Manager' on module 
> '/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp'. 
> 4. Running pass 'Simplify the CFG' on function 
> '@_ZL16RegisterHandlersv' #0 0x0000555b7ea0366a 
> llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2cfc66a) 
> #1 0x0000555b7ea013a5 llvm::sys::RunSignalHandlers() 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2cfa3a5) 
> #2 0x0000555b7ea014c7 SignalHandler(int) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2cfa4c7) 
> #3 0x00007f62544fa0e0 __restore_rt 
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x110e0) #4 0x00007f62532b9fff 
> raise (/lib/x86_64-linux-gnu/libc.so.6+0x32fff) #5 0x00007f62532bb42a 
> abort (/lib/x86_64-linux-gnu/libc.so.6+0x3442a) #6 0x00007f62532b2e67 
> (/lib/x86_64-linux-gnu/libc.so.6+0x2be67) #7 0x00007f62532b2f12 
> (/lib/x86_64-linux-gnu/libc.so.6+0x2bf12) #8 0x0000555b7dda0fd0 
> llvm::parseWidenableBranch(llvm::User*, llvm::Use*&, llvm::Use*&, 
> llvm::BasicBlock*&, llvm::BasicBlock*&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2099fd0) 
> #9 0x0000555b7dda12a0 llvm::parseWidenableBranch(llvm::User const*, 
> llvm::Value*&, llvm::Value*&, llvm::BasicBlock*&, llvm::BasicBlock*&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x209a2a0) 
> #10 0x0000555b7eafb640 
> SimplifyCondBranchToCondBranch(llvm::BranchInst*, llvm::BranchInst*, 
> llvm::DataLayout const&, llvm::TargetTransformInfo const&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2df4640) 
> #11 0x0000555b7eb09676 llvm::simplifyCFG(llvm::BasicBlock*, 
> llvm::TargetTransformInfo const&, llvm::SimplifyCFGOptions const&, 
> llvm::SmallPtrSetImpl<llvm::BasicBlock*>*) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2e02676) 
> #12 0x0000555b7e946457 iterativelySimplifyCFG(llvm::Function&, 
> llvm::TargetTransformInfo const&, llvm::SimplifyCFGOptions const&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2c3f457) 
> #13 0x0000555b7e947181 (anonymous 
> namespace)::CFGSimplifyPass::runOnFunction(llvm::Function&) 
> (/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-10+0x2c40181)
>
> On Thu, Nov 21, 2019 at 3:07 PM Philip Reames via llvm-commits 
> <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
>
>
>     Author: Philip Reames
>     Date: 2019-11-21T15:07:30-08:00
>     New Revision: 8293f7434577e23a07284686f5b54079e22e6a91
>
>     URL:
>     https://github.com/llvm/llvm-project/commit/8293f7434577e23a07284686f5b54079e22e6a91
>     DIFF:
>     https://github.com/llvm/llvm-project/commit/8293f7434577e23a07284686f5b54079e22e6a91.diff
>
>     LOG: Further cleanup manipulation of widenable branches [NFC]
>
>     This is a follow on to aaea24802bf5.  In post commit discussion,
>     Artur and I realized we could cleanup the code using Uses; this
>     patch does so.
>
>     Added:
>
>
>     Modified:
>         llvm/include/llvm/Analysis/GuardUtils.h
>         llvm/lib/Analysis/GuardUtils.cpp
>         llvm/lib/Transforms/Utils/GuardUtils.cpp
>
>     Removed:
>
>
>
>     ################################################################################
>     diff  --git a/llvm/include/llvm/Analysis/GuardUtils.h
>     b/llvm/include/llvm/Analysis/GuardUtils.h
>     index f4492c72ce63..b83211535ec2 100644
>     --- a/llvm/include/llvm/Analysis/GuardUtils.h
>     +++ b/llvm/include/llvm/Analysis/GuardUtils.h
>     @@ -15,6 +15,7 @@
>      namespace llvm {
>
>      class BasicBlock;
>     +class Use;
>      class User;
>      class Value;
>
>     @@ -43,6 +44,11 @@ bool parseWidenableBranch(const User *U, Value
>     *&Condition,
>                                Value *&WidenableCondition, BasicBlock
>     *&IfTrueBB,
>                                BasicBlock *&IfFalseBB);
>
>     +/// Analgous to the above, but return the Uses so that that they
>     can be
>     +/// modified. Unlike previous version, Condition is optional and
>     may be null.
>     +bool parseWidenableBranch(User *U, Use *&Cond, Use *&WC,
>     BasicBlock *&IfTrueBB,
>     +                          BasicBlock *&IfFalseBB);
>     +
>      } // llvm
>
>      #endif // LLVM_ANALYSIS_GUARDUTILS_H
>
>     diff  --git a/llvm/lib/Analysis/GuardUtils.cpp
>     b/llvm/lib/Analysis/GuardUtils.cpp
>     index d4a86e18997e..18141069f6a4 100644
>     --- a/llvm/lib/Analysis/GuardUtils.cpp
>     +++ b/llvm/lib/Analysis/GuardUtils.cpp
>     @@ -44,11 +44,35 @@ bool llvm::isGuardAsWidenableBranch(const User
>     *U) {
>      bool llvm::parseWidenableBranch(const User *U, Value *&Condition,
>                                      Value *&WidenableCondition,
>                                      BasicBlock *&IfTrueBB, BasicBlock
>     *&IfFalseBB) {
>     -  if (match(U,
>     m_Br(m_Intrinsic<Intrinsic::experimental_widenable_condition>(),
>     -                    IfTrueBB, IfFalseBB)) &&
>     - cast<BranchInst>(U)->getCondition()->hasOneUse()) {
>     -    WidenableCondition = cast<BranchInst>(U)->getCondition();
>     -    Condition = ConstantInt::getTrue(IfTrueBB->getContext());
>     +
>     +  Use *C, *WC;
>     +  if (parseWidenableBranch(const_cast<User*>(U), C, WC, IfTrueBB,
>     IfFalseBB)) {
>     +    if (C)
>     +      Condition = C->get();
>     +    else
>     +      Condition = ConstantInt::getTrue(IfTrueBB->getContext());
>     +    WidenableCondition = WC->get();
>     +    return true;
>     +  }
>     +  return false;
>     +}
>     +
>     +bool llvm::parseWidenableBranch(User *U, Use *&C,Use *&WC,
>     +                                BasicBlock *&IfTrueBB, BasicBlock
>     *&IfFalseBB) {
>     +
>     +  auto *BI = dyn_cast<BranchInst>(U);
>     +  if (!BI || !BI->isConditional())
>     +    return false;
>     +  auto *Cond = BI->getCondition();
>     +  if (!Cond->hasOneUse())
>     +    return false;
>     +
>     +  IfTrueBB = BI->getSuccessor(0);
>     +  IfFalseBB = BI->getSuccessor(1);
>     +
>     +  if (match(Cond,
>     m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
>     +    WC = &BI->getOperandUse(0);
>     +    C = nullptr;
>          return true;
>        }
>
>     @@ -57,19 +81,23 @@ bool llvm::parseWidenableBranch(const User *U,
>     Value *&Condition,
>        // 2) br (i1 (and WC(), B)), label %IfTrue, label %IfFalse
>        // We do not check for more generalized and trees as we should
>     canonicalize
>        // to the form above in instcombine. (TODO)
>     -  if (!match(U, m_Br(m_And(m_Value(Condition),
>     m_Value(WidenableCondition)),
>     -                     IfTrueBB, IfFalseBB)))
>     +  Value *A, *B;
>     +  if (!match(Cond, m_And(m_Value(A), m_Value(B))))
>          return false;
>     -  if (!match(WidenableCondition,
>     -  m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
>     -    if (!match(Condition,
>     -  m_Intrinsic<Intrinsic::experimental_widenable_condition>()))
>     -      return false;
>     -    std::swap(Condition, WidenableCondition);
>     +  auto *And = cast<Instruction>(Cond);
>     +
>     +  if (match(A,
>     m_Intrinsic<Intrinsic::experimental_widenable_condition>()) &&
>     +      A->hasOneUse()) {
>     +    WC = &And->getOperandUse(0);
>     +    C = &And->getOperandUse(1);
>     +    return true;
>        }
>     -
>     -  // For the branch to be (easily) widenable, it must not
>     correlate with other
>     -  // branches.  Thus, the widenable condition must have a single use.
>     -  return (WidenableCondition->hasOneUse() &&
>     - cast<BranchInst>(U)->getCondition()->hasOneUse());
>     +
>     +  if (match(B,
>     m_Intrinsic<Intrinsic::experimental_widenable_condition>()) &&
>     +      B->hasOneUse()) {
>     +    WC = &And->getOperandUse(1);
>     +    C = &And->getOperandUse(0);
>     +    return true;
>     +  }
>     +  return false;
>      }
>
>     diff  --git a/llvm/lib/Transforms/Utils/GuardUtils.cpp
>     b/llvm/lib/Transforms/Utils/GuardUtils.cpp
>     index 241bfbf80bdf..4cfc9358499a 100644
>     --- a/llvm/lib/Transforms/Utils/GuardUtils.cpp
>     +++ b/llvm/lib/Transforms/Utils/GuardUtils.cpp
>     @@ -87,23 +87,20 @@ void llvm::widenWidenableBranch(BranchInst
>     *WidenableBR, Value *NewCond) {
>        // condition, but that doesn't match the pattern
>     parseWidenableBranch expects
>        // so we have to be more sophisticated.
>
>     -  if (match(WidenableBR->getCondition(),
>     - m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
>     +  Use *C, *WC;
>     +  BasicBlock *IfTrueBB, *IfFalseBB;
>     +  parseWidenableBranch(WidenableBR, C, WC, IfTrueBB, IfFalseBB);
>     +  if (!C) {
>     +    // br (wc()), ... form
>          IRBuilder<> B(WidenableBR);
>     -    WidenableBR->setCondition(B.CreateAnd(NewCond,
>     - WidenableBR->getCondition()));
>     +    WidenableBR->setCondition(B.CreateAnd(NewCond, WC->get()));
>        } else {
>     +    // br (wc & C), ... form
>     +    IRBuilder<> B(WidenableBR);
>     +    C->set(B.CreateAnd(NewCond, C->get()));
>          Instruction *WCAnd =
>     cast<Instruction>(WidenableBR->getCondition());
>          // Condition is only guaranteed to dominate branch
>     -    WCAnd->moveBefore(WidenableBR);
>     -    IRBuilder<> B(WCAnd);
>     -    const bool Op0IsWC =
>     -      match(WCAnd->getOperand(0),
>     - m_Intrinsic<Intrinsic::experimental_widenable_condition>());
>     -    const unsigned CondOpIdx = Op0IsWC ? 1 : 0;
>     -    Value *OldCond = WCAnd->getOperand(CondOpIdx);
>     -    NewCond = B.CreateAnd(NewCond, OldCond);
>     -    WCAnd->setOperand(CondOpIdx, NewCond);
>     +    WCAnd->moveBefore(WidenableBR);
>        }
>        assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
>      }
>     @@ -111,20 +108,19 @@ void llvm::widenWidenableBranch(BranchInst
>     *WidenableBR, Value *NewCond) {
>      void llvm::setWidenableBranchCond(BranchInst *WidenableBR, Value
>     *NewCond) {
>        assert(isWidenableBranch(WidenableBR) && "precondition");
>
>     -  if (match(WidenableBR->getCondition(),
>     - m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
>     +  Use *C, *WC;
>     +  BasicBlock *IfTrueBB, *IfFalseBB;
>     +  parseWidenableBranch(WidenableBR, C, WC, IfTrueBB, IfFalseBB);
>     +  if (!C) {
>     +    // br (wc()), ... form
>          IRBuilder<> B(WidenableBR);
>     -    WidenableBR->setCondition(B.CreateAnd(NewCond,
>     - WidenableBR->getCondition()));
>     +    WidenableBR->setCondition(B.CreateAnd(NewCond, WC->get()));
>        } else {
>     +    // br (wc & C), ... form
>          Instruction *WCAnd =
>     cast<Instruction>(WidenableBR->getCondition());
>          // Condition is only guaranteed to dominate branch
>          WCAnd->moveBefore(WidenableBR);
>     -    const bool Op0IsWC =
>     -      match(WCAnd->getOperand(0),
>     - m_Intrinsic<Intrinsic::experimental_widenable_condition>());
>     -    const unsigned CondOpIdx = Op0IsWC ? 1 : 0;
>     -    WCAnd->setOperand(CondOpIdx, NewCond);
>     +    C->set(NewCond);
>        }
>        assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
>      }
>
>
>
>     _______________________________________________
>     llvm-commits mailing list
>     llvm-commits at lists.llvm.org <mailto: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/20191122/61043b45/attachment.html>


More information about the llvm-commits mailing list