[llvm] r298711 - [InstCombine] Provide a way to calculate KnownZero/One for Add/Sub in SimplifyDemandedUseBits without recursing into ComputeKnownBits

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 15:34:46 PDT 2017


That seems highly unlikely to be related. The code I modified would be
called from clangs CodeGen path not from anything in Sema.

~Craig

On Fri, Mar 24, 2017 at 3:28 PM, Vitaly Buka <vitalybuka at google.com> wrote:

> Thanks for revert.
> Not sure, but this may be related as well
>
> http://lab.llvm.org:8011/builders/sanitizer-ppc64le-
> linux/builds/1847/steps/bootstrap%20clang/logs/stdio
>
> [100%] Cleaning compiler-rt...
> [100%] Building CXX object tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/COFFDump.cpp.o
> [100%] Linking CXX executable ../../bin/sancov
> [100%] Performing build step for 'compiler-rt'
> Scanning dependencies of target RTSanitizerCommonLibc.powerpc64le
> [  1%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.powerpc64le.dir/sanitizer_common_libcdep.cc.o
> #0 0x0000000011bd5410 PrintStackTrace /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/lib/Support/Unix/Signals.inc:402:13
> #1 0x0000000011bd5410 PrintStackTraceSignalHandler(void*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/lib/Support/Unix/Signals.inc:465:0
> #2 0x0000000011bd5864 RunSignalHandlers /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/lib/Support/Signals.cpp:45:5
> #3 0x0000000011bd5864 SignalHandler(int) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/lib/Support/Unix/Signals.inc:246:0
> #4 0x00003fff8e2c0478  0x478 getPointer
> #5 0x00003fff8e2c0478 /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/include/llvm/ADT/PointerIntPair.h:56:58 getPrefix
> #6 0x00003fff8e2c0478 /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/include/clang/AST/NestedNameSpecifier.h:162:0 getPrefix
> #7 0x00003fff8e2c0478 /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/include/clang/AST/NestedNameSpecifier.h:314:0 clang::NestedNameSpecifierLoc::getSourceRange() const
> #8 0x00003fff8e2c0478 /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/AST/NestedNameSpecifier.cpp:400:0
> #9 0x00003fff8e2c0478 getBeginLoc /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/include/clang/AST/NestedNameSpecifier.h:283:12
> #10 0x00003fff8e2c0478 clang::MemberExpr::getLocStart() const /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/AST/Expr.cpp:1500:0
> #11 0x0000000013ac4ba0 getSourceRangeImpl<clang::MemberExpr> /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/AST/Stmt.cpp:240:53
> #12 0x0000000013ac4ba0 clang::Stmt::getSourceRange() const /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build64/tools/clang/include/clang/AST/StmtNodes.inc:597:0
> #13 0x0000010004c4acb8
> #14 0x0000000013a0d79c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/TreeTransform.h:9041:31
> #15 0x0000000013aee72c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build64/tools/clang/include/clang/AST/StmtNodes.inc:329:1
> #16 0x000000001341d658 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/TreeTransform.h:3242:35
> #17 0x0000000013413488 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/TreeTransform.h:6355:38
> #18 0x0000000013412b4c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/TreeTransform.h:6342:23
> #19 0x000000001342dab0 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build64/tools/clang/include/clang/AST/StmtNodes.inc:79:1
> #20 0x0000000013432d5c clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:2733:23
> #21 0x0000000013412e3c clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:3887:23
> #22 0x0000000013412a98 clang::Sema::PerformPendingInstantiations(bool) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5131:7
> #23 0x0000000013453ebc clang::Sema::ActOnEndOfTranslationUnit() /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Sema/Sema.cpp:725:5
> #24 0x000000001344b71c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Parse/Parser.cpp:618:15
> #25 0x0000000012e0c184 clang::ParseAST(clang::Sema&, bool, bool) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18
> #26 0x0000000012b3bd38 clang::ASTFrontendAction::ExecuteAction() /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:611:3
> #27 0x0000000012b3589c clang::CodeGenAction::ExecuteAction() /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:989:28
> #28 0x0000000012222a84 clang::FrontendAction::Execute() /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:512:8
> #29 0x00000000125e1118 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:959:11
> #30 0x00000000122220c4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:249:25
> #31 0x00000000121dc6a8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/tools/driver/cc1_main.cpp:221:13
> #32 0x00000000122cd724 ExecuteCC1Tool /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/tools/driver/driver.cpp:299:12
> #33 0x00000000122cd724 main /home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm/tools/clang/tools/driver/driver.cpp:380:0
> #34 0x000000001042ed64 generic_start_main.isra.0 (/home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build64/bin/clang-5.0+0x1042ed64)
> #35 0x000000001042bdc4 __libc_start_main (/home/buildbots/ppc64le-sanitizer/sanitizer-ppc64le/build
>
>
> On Fri, Mar 24, 2017 at 3:04 PM Vitaly Buka <vitalybuka at google.com> wrote:
>
>> These tests are broken after the patch
>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-
>> linux-autoconf/builds/6467/steps/test%20tsan%20in%
>> 20debug%20compiler-rt%20build/logs/stdio
>>
>> Scanning dependencies of target TsanUnitTests
>> [ 90%] Built target TsanUnitTests
>> [ 90%] Built target SanitizerLintCheck
>> -- libcxx_tsan_x86_64 configure command succeeded.  See also /mnt/b/sanitizer-buildbot4/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/lib/tsan/libcxx_tsan_x86_64/src/libcxx_tsan_x86_64-stamp/libcxx_tsan_x86_64-configure-*.log
>> [ 90%] Performing build step for 'libcxx_tsan_x86_64'make[7]: *** [lib/tsan/CMakeFiles/GotsanRuntimeCheck] Error 139
>> make[6]: *** [lib/tsan/CMakeFiles/GotsanRuntimeCheck.dir/all] Error 2
>> make[6]: *** Waiting for unfinished jobs....
>> -- libcxx_tsan_x86_64 build command succeeded.  See also /mnt/b/sanitizer-buildbot4/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/lib/tsan/libcxx_tsan_x86_64/src/libcxx_tsan_x86_64-stamp/libcxx_tsan_x86_64-build-*.log
>> [ 90%] Performing install step for 'libcxx_tsan_x86_64'
>> -- libcxx_tsan_x86_64 install command succeeded.  See also /mnt/b/sanitizer-buildbot4/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/lib/tsan/libcxx_tsan_x86_64/src/libcxx_tsan_x86_64-stamp/libcxx_tsan_x86_64-install-*.log
>> [ 95%] Completed 'libcxx_tsan_x86_64'
>> [ 95%] Built target libcxx_tsan_x86_64
>> make[5]: *** [test/tsan/CMakeFiles/check-tsan.dir/rule] Error 2
>> make[4]: *** [check-tsan] Error 2
>> make[3]: *** [tools/clang/runtime/CMakeFiles/check-tsan] Error 2
>> make[2]: *** [tools/clang/runtime/CMakeFiles/check-tsan.dir/all] Error 2
>> make[1]: *** [tools/clang/runtime/CMakeFiles/check-tsan.dir/rule] Error 2
>> make: *** [check-tsan] Error 2
>> + echo @@@STEP_FAILURE@@@
>> @@@STEP_FAILURE@@@
>>
>>
>> Reproducible locally with
>>
>> MAKE_JOBS=30 BUILDBOT_REVISION=298711 BUILDBOT_CLOBBER= llvm/projects/zorg/zorg/buildbot/builders/sanitizers/buildbot_standard.sh
>>
>>
>> On Fri, Mar 24, 2017 at 10:09 AM Craig Topper via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> Author: ctopper
>>> Date: Fri Mar 24 11:56:51 2017
>>> New Revision: 298711
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=298711&view=rev
>>> Log:
>>> [InstCombine] Provide a way to calculate KnownZero/One for Add/Sub in
>>> SimplifyDemandedUseBits without recursing into ComputeKnownBits
>>>
>>> SimplifyDemandedUseBits for Add/Sub already recursed down LHS and RHS
>>> for simplifying bits. If that didn't provide any simplifications we fall
>>> back to calling computeKnownBits which will recurse again. Instead just
>>> take the known bits for LHS and RHS we already have and call into a new
>>> function in ValueTracking that can calculate the known bits given the
>>> LHS/RHS bits.
>>>
>>>
>>>
>>>
>>> Modified:
>>>     llvm/trunk/include/llvm/Analysis/ValueTracking.h
>>>     llvm/trunk/lib/Analysis/ValueTracking.cpp
>>>     llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.
>>> cpp
>>>
>>> Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
>>> llvm/Analysis/ValueTracking.h?rev=298711&r1=298710&r2=298711&view=diff
>>> ============================================================
>>> ==================
>>> --- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
>>> +++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Fri Mar 24
>>> 11:56:51 2017
>>> @@ -55,6 +55,11 @@ template <typename T> class ArrayRef;
>>>                          const Instruction *CxtI = nullptr,
>>>                          const DominatorTree *DT = nullptr,
>>>                          OptimizationRemarkEmitter *ORE = nullptr);
>>> +  /// Compute known bits for add/sub using LHS/RHS known bits.
>>> +  void computeKnownBitsForAddSub(bool Add, bool NSW,
>>> +                                 APInt &KnownZero, APInt &KnownOne,
>>> +                                 APInt &LHSKnownZero, APInt
>>> &LHSKnownOne,
>>> +                                 APInt &RHSKnownZero, APInt
>>> &RHSKnownOne);
>>>    /// Compute known bits from the range metadata.
>>>    /// \p KnownZero the set of bits that are known to be zero
>>>    /// \p KnownOne the set of bits that are known to be one
>>>
>>> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
>>> Analysis/ValueTracking.cpp?rev=298711&r1=298710&r2=298711&view=diff
>>> ============================================================
>>> ==================
>>> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
>>> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Mar 24 11:56:51 2017
>>> @@ -250,37 +250,29 @@ unsigned llvm::ComputeNumSignBits(const
>>>    return ::ComputeNumSignBits(V, Depth, Query(DL, AC, safeCxtI(V,
>>> CxtI), DT));
>>>  }
>>>
>>> -static void computeKnownBitsAddSub(bool Add, const Value *Op0, const
>>> Value *Op1,
>>> -                                   bool NSW,
>>> -                                   APInt &KnownZero, APInt &KnownOne,
>>> -                                   APInt &KnownZero2, APInt &KnownOne2,
>>> -                                   unsigned Depth, const Query &Q) {
>>> -  unsigned BitWidth = KnownZero.getBitWidth();
>>> -
>>> -  // If an initial sequence of bits in the result is not needed, the
>>> -  // corresponding bits in the operands are not needed.
>>> -  APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
>>> -  computeKnownBits(Op0, LHSKnownZero, LHSKnownOne, Depth + 1, Q);
>>> -  computeKnownBits(Op1, KnownZero2, KnownOne2, Depth + 1, Q);
>>> -
>>> +/// Compute known bits for add/sub using LHS/RHS known bits.
>>> +void llvm::computeKnownBitsForAddSub(bool Add, bool NSW,
>>> +                                     APInt &KnownZero, APInt &KnownOne,
>>> +                                     APInt &LHSKnownZero, APInt
>>> &LHSKnownOne,
>>> +                                     APInt &RHSKnownZero, APInt
>>> &RHSKnownOne) {
>>>    // Carry in a 1 for a subtract, rather than a 0.
>>>    uint64_t CarryIn = 0;
>>>    if (!Add) {
>>>      // Sum = LHS + ~RHS + 1
>>> -    std::swap(KnownZero2, KnownOne2);
>>> +    std::swap(RHSKnownZero, RHSKnownOne);
>>>      CarryIn = 1;
>>>    }
>>>
>>> -  APInt PossibleSumZero = ~LHSKnownZero + ~KnownZero2 + CarryIn;
>>> -  APInt PossibleSumOne = LHSKnownOne + KnownOne2 + CarryIn;
>>> +  APInt PossibleSumZero = ~LHSKnownZero + ~RHSKnownZero + CarryIn;
>>> +  APInt PossibleSumOne = LHSKnownOne + RHSKnownOne + CarryIn;
>>>
>>>    // Compute known bits of the carry.
>>> -  APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^ KnownZero2);
>>> -  APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ KnownOne2;
>>> +  APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^
>>> RHSKnownZero);
>>> +  APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ RHSKnownOne;
>>>
>>>    // Compute set of known bits (where all three relevant bits are
>>> known).
>>>    APInt LHSKnown = LHSKnownZero | LHSKnownOne;
>>> -  APInt RHSKnown = KnownZero2 | KnownOne2;
>>> +  APInt RHSKnown = RHSKnownZero | RHSKnownOne;
>>>    APInt CarryKnown = CarryKnownZero | CarryKnownOne;
>>>    APInt Known = LHSKnown & RHSKnown & CarryKnown;
>>>
>>> @@ -296,14 +288,36 @@ static void computeKnownBitsAddSub(bool
>>>      if (NSW) {
>>>        // Adding two non-negative numbers, or subtracting a negative
>>> number from
>>>        // a non-negative one, can't wrap into negative.
>>> -      if (LHSKnownZero.isNegative() && KnownZero2.isNegative())
>>> +      if (LHSKnownZero.isNegative() && RHSKnownZero.isNegative())
>>>          KnownZero.setSignBit();
>>>        // Adding two negative numbers, or subtracting a non-negative
>>> number from
>>>        // a negative one, can't wrap into non-negative.
>>> -      else if (LHSKnownOne.isNegative() && KnownOne2.isNegative())
>>> +      else if (LHSKnownOne.isNegative() && RHSKnownOne.isNegative())
>>>          KnownOne.setSignBit();
>>>      }
>>>    }
>>> +
>>> +  // Put the RHS/LHS back how we found them.
>>> +  if (!Add) {
>>> +    std::swap(RHSKnownZero, RHSKnownOne);
>>> +  }
>>> +}
>>> +
>>> +static void computeKnownBitsAddSub(bool Add, const Value *Op0, const
>>> Value *Op1,
>>> +                                   bool NSW,
>>> +                                   APInt &KnownZero, APInt &KnownOne,
>>> +                                   APInt &KnownZero2, APInt &KnownOne2,
>>> +                                   unsigned Depth, const Query &Q) {
>>> +  unsigned BitWidth = KnownZero.getBitWidth();
>>> +
>>> +  // If an initial sequence of bits in the result is not needed, the
>>> +  // corresponding bits in the operands are not needed.
>>> +  APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
>>> +  computeKnownBits(Op0, LHSKnownZero, LHSKnownOne, Depth + 1, Q);
>>> +  computeKnownBits(Op1, KnownZero2, KnownOne2, Depth + 1, Q);
>>> +
>>> +  computeKnownBitsForAddSub(Add, NSW, KnownZero, KnownOne, LHSKnownZero,
>>> +                            LHSKnownOne, KnownZero2, KnownOne2);
>>>  }
>>>
>>>  static void computeKnownBitsMul(const Value *Op0, const Value *Op1,
>>> bool NSW,
>>>
>>> Modified: llvm/trunk/lib/Transforms/InstCombine/
>>> InstCombineSimplifyDemanded.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
>>> Transforms/InstCombine/InstCombineSimplifyDemanded.
>>> cpp?rev=298711&r1=298710&r2=298711&view=diff
>>> ============================================================
>>> ==================
>>> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
>>> (original)
>>> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
>>> Fri Mar 24 11:56:51 2017
>>> @@ -538,7 +538,7 @@ Value *InstCombiner::SimplifyDemandedUse
>>>                                 LHSKnownZero, LHSKnownOne, Depth + 1) ||
>>>            ShrinkDemandedConstant(I, 1, DemandedFromOps) ||
>>>            SimplifyDemandedBits(I->getOperandUse(1), DemandedFromOps,
>>> -                               LHSKnownZero, LHSKnownOne, Depth + 1)) {
>>> +                               RHSKnownZero, RHSKnownOne, Depth + 1)) {
>>>          // Disable the nsw and nuw flags here: We can no longer
>>> guarantee that
>>>          // we won't wrap after simplification. Removing the nsw/nuw
>>> flags is
>>>          // legal here because the top bit is not demanded.
>>> @@ -549,9 +549,10 @@ Value *InstCombiner::SimplifyDemandedUse
>>>        }
>>>      }
>>>
>>> -    // Otherwise just hand the add/sub off to computeKnownBits to fill
>>> in
>>> -    // the known zeros and ones.
>>> -    computeKnownBits(V, KnownZero, KnownOne, Depth, CxtI);
>>> +    // Otherwise compute the known bits using the RHS/LHS known bits.
>>> +    bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoSignedWrap();
>>> +    computeKnownBitsForAddSub(V, NSW, KnownZero, KnownOne, LHSKnownZero,
>>> +                              LHSKnownOne, RHSKnownZero, RHSKnownOne);
>>>      break;
>>>    }
>>>    case Instruction::Shl:
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://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/20170324/e3f8f0d5/attachment.html>


More information about the llvm-commits mailing list