[clang] [llvm] [ValueTracking] Restore isKnownNonZero parameter order. (PR #88873)
https://github.com/hvdijk closed https://github.com/llvm/llvm-project/pull/88873 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Restore isKnownNonZero parameter order. (PR #88873)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/88873 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Restore isKnownNonZero parameter order. (PR #88873)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Harald van Dijk (hvdijk) Changes Prior to #85863, the required parameters of llvm::isKnownNonZero were Value and DataLayout. After, they are Value, Depth, and SimplifyQuery, where SimplifyQuery is implicitly constructible from DataLayout. The change to move Depth before SimplifyQuery needed callers to be updated unnecessarily, and as commented in #85863, we actually want Depth to be after SimplifyQuery anyway so that it can be defaulted and the caller does not need to specify it. --- Patch is 47.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88873.diff 22 Files Affected: - (modified) clang/lib/CodeGen/CGCall.cpp (+1-2) - (modified) llvm/include/llvm/Analysis/ValueTracking.h (+1-1) - (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+1-2) - (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+12-13) - (modified) llvm/lib/Analysis/LazyValueInfo.cpp (+2-3) - (modified) llvm/lib/Analysis/Loads.cpp (+2-2) - (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+1-1) - (modified) llvm/lib/Analysis/ValueTracking.cpp (+53-53) - (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+1-1) - (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-1) - (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+1-1) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp (+1-1) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+2-2) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+4-7) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+9-9) - (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+1-2) - (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+10-10) - (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+1-1) - (modified) llvm/unittests/Analysis/ValueTrackingTest.cpp (+5-8) ``diff diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 7a0bc6fa77b889..3f5463a9a70e9d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4124,8 +4124,7 @@ static bool isProvablyNull(llvm::Value *addr) { } static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) { - return llvm::isKnownNonZero(Addr.getBasePointer(), /*Depth=*/0, - CGF.CGM.getDataLayout()); + return llvm::isKnownNonZero(Addr.getBasePointer(), CGF.CGM.getDataLayout()); } /// Emit the actual writing-back of a writeback. diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index 9db0894162afca..e1c41b3b55ccfb 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -124,7 +124,7 @@ bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI); /// specified, perform context-sensitive analysis and return true if the /// pointer couldn't possibly be null at the specified instruction. /// Supports values with integer or pointer type and vectors of integers. -bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q); +bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0); /// Return true if the two given values are negation. /// Currently can recoginze Value pair: diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index b082dfe8fbd217..16ee2ca49d0ece 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1283,8 +1283,7 @@ AliasResult BasicAAResult::aliasGEP( // VarIndex = Scale*V. const VariableGEPIndex &Var = DecompGEP1.VarIndices[0]; if (Var.Val.TruncBits == 0 && -isKnownNonZero(Var.Val.V, /*Depth=*/0, - SimplifyQuery(DL, DT, &AC, Var.CxtI))) { +isKnownNonZero(Var.Val.V, SimplifyQuery(DL, DT, &AC, Var.CxtI))) { // Check if abs(V*Scale) >= abs(Scale) holds in the presence of // potentially wrapping math. auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) { diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4e6e666922671d..8955de6375dec4 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1586,10 +1586,10 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, if (match(UnsignedICmp, m_c_ICmp(UnsignedPred, m_Specific(Y), m_Specific(A { if (UnsignedPred == ICmpInst::ICMP_UGE && IsAnd && - EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, /*Depth=*/0, Q)) + EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, Q))
[clang] [llvm] [ValueTracking] Restore isKnownNonZero parameter order. (PR #88873)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Harald van Dijk (hvdijk) Changes Prior to #85863, the required parameters of llvm::isKnownNonZero were Value and DataLayout. After, they are Value, Depth, and SimplifyQuery, where SimplifyQuery is implicitly constructible from DataLayout. The change to move Depth before SimplifyQuery needed callers to be updated unnecessarily, and as commented in #85863, we actually want Depth to be after SimplifyQuery anyway so that it can be defaulted and the caller does not need to specify it. --- Patch is 47.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88873.diff 22 Files Affected: - (modified) clang/lib/CodeGen/CGCall.cpp (+1-2) - (modified) llvm/include/llvm/Analysis/ValueTracking.h (+1-1) - (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+1-2) - (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+12-13) - (modified) llvm/lib/Analysis/LazyValueInfo.cpp (+2-3) - (modified) llvm/lib/Analysis/Loads.cpp (+2-2) - (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+1-1) - (modified) llvm/lib/Analysis/ValueTracking.cpp (+53-53) - (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+1-1) - (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-1) - (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+1-1) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp (+1-1) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+2-2) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+4-7) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+9-9) - (modified) llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp (+1-2) - (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+10-10) - (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+1-1) - (modified) llvm/unittests/Analysis/ValueTrackingTest.cpp (+5-8) ``diff diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 7a0bc6fa77b889..3f5463a9a70e9d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4124,8 +4124,7 @@ static bool isProvablyNull(llvm::Value *addr) { } static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) { - return llvm::isKnownNonZero(Addr.getBasePointer(), /*Depth=*/0, - CGF.CGM.getDataLayout()); + return llvm::isKnownNonZero(Addr.getBasePointer(), CGF.CGM.getDataLayout()); } /// Emit the actual writing-back of a writeback. diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index 9db0894162afca..e1c41b3b55ccfb 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -124,7 +124,7 @@ bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI); /// specified, perform context-sensitive analysis and return true if the /// pointer couldn't possibly be null at the specified instruction. /// Supports values with integer or pointer type and vectors of integers. -bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q); +bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0); /// Return true if the two given values are negation. /// Currently can recoginze Value pair: diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index b082dfe8fbd217..16ee2ca49d0ece 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1283,8 +1283,7 @@ AliasResult BasicAAResult::aliasGEP( // VarIndex = Scale*V. const VariableGEPIndex &Var = DecompGEP1.VarIndices[0]; if (Var.Val.TruncBits == 0 && -isKnownNonZero(Var.Val.V, /*Depth=*/0, - SimplifyQuery(DL, DT, &AC, Var.CxtI))) { +isKnownNonZero(Var.Val.V, SimplifyQuery(DL, DT, &AC, Var.CxtI))) { // Check if abs(V*Scale) >= abs(Scale) holds in the presence of // potentially wrapping math. auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) { diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4e6e666922671d..8955de6375dec4 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1586,10 +1586,10 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, if (match(UnsignedICmp, m_c_ICmp(UnsignedPred, m_Specific(Y), m_Specific(A { if (UnsignedPred == ICmpInst::ICMP_UGE && IsAnd && - EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, /*Depth=*/0, Q)) + EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, Q)) re
[clang] [llvm] [ValueTracking] Restore isKnownNonZero parameter order. (PR #88873)
https://github.com/hvdijk created https://github.com/llvm/llvm-project/pull/88873 Prior to #85863, the required parameters of llvm::isKnownNonZero were Value and DataLayout. After, they are Value, Depth, and SimplifyQuery, where SimplifyQuery is implicitly constructible from DataLayout. The change to move Depth before SimplifyQuery needed callers to be updated unnecessarily, and as commented in #85863, we actually want Depth to be after SimplifyQuery anyway so that it can be defaulted and the caller does not need to specify it. >From 6763d8cce44be02e9065c9c640736ac85ffcf8a2 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Tue, 16 Apr 2024 12:06:31 +0100 Subject: [PATCH] [ValueTracking] Restore isKnownNonZero parameter order. Prior to #85863, the required parameters of llvm::isKnownNonZero were Value and DataLayout. After, they are Value, Depth, and SimplifyQuery, where SimplifyQuery is implicitly constructible from DataLayout. The change to move Depth before SimplifyQuery needed callers to be updated unnecessarily, and as commented in #85863, we actually want Depth to be after SimplifyQuery anyway so that it can be defaulted and the caller does not need to specify it. --- clang/lib/CodeGen/CGCall.cpp | 3 +- llvm/include/llvm/Analysis/ValueTracking.h| 2 +- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 3 +- llvm/lib/Analysis/InstructionSimplify.cpp | 25 ++--- llvm/lib/Analysis/LazyValueInfo.cpp | 5 +- llvm/lib/Analysis/Loads.cpp | 4 +- llvm/lib/Analysis/ScalarEvolution.cpp | 2 +- llvm/lib/Analysis/ValueTracking.cpp | 106 +- llvm/lib/CodeGen/CodeGenPrepare.cpp | 2 +- .../Transforms/IPO/AttributorAttributes.cpp | 2 +- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 2 +- .../InstCombine/InstCombineAddSub.cpp | 2 +- .../InstCombine/InstCombineAndOrXor.cpp | 4 +- .../InstCombine/InstCombineCalls.cpp | 11 +- .../InstCombine/InstCombineCompares.cpp | 18 +-- .../Transforms/InstCombine/InstCombinePHI.cpp | 3 +- .../InstCombine/InstructionCombining.cpp | 2 +- .../Instrumentation/MemorySanitizer.cpp | 4 +- .../Utils/PromoteMemoryToRegister.cpp | 2 +- .../lib/Transforms/Utils/SimplifyLibCalls.cpp | 20 ++-- .../Transforms/Vectorize/VectorCombine.cpp| 2 +- llvm/unittests/Analysis/ValueTrackingTest.cpp | 13 +-- 22 files changed, 113 insertions(+), 124 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 7a0bc6fa77b889..3f5463a9a70e9d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4124,8 +4124,7 @@ static bool isProvablyNull(llvm::Value *addr) { } static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) { - return llvm::isKnownNonZero(Addr.getBasePointer(), /*Depth=*/0, - CGF.CGM.getDataLayout()); + return llvm::isKnownNonZero(Addr.getBasePointer(), CGF.CGM.getDataLayout()); } /// Emit the actual writing-back of a writeback. diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index 9db0894162afca..e1c41b3b55ccfb 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -124,7 +124,7 @@ bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI); /// specified, perform context-sensitive analysis and return true if the /// pointer couldn't possibly be null at the specified instruction. /// Supports values with integer or pointer type and vectors of integers. -bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q); +bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0); /// Return true if the two given values are negation. /// Currently can recoginze Value pair: diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index b082dfe8fbd217..16ee2ca49d0ece 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1283,8 +1283,7 @@ AliasResult BasicAAResult::aliasGEP( // VarIndex = Scale*V. const VariableGEPIndex &Var = DecompGEP1.VarIndices[0]; if (Var.Val.TruncBits == 0 && -isKnownNonZero(Var.Val.V, /*Depth=*/0, - SimplifyQuery(DL, DT, &AC, Var.CxtI))) { +isKnownNonZero(Var.Val.V, SimplifyQuery(DL, DT, &AC, Var.CxtI))) { // Check if abs(V*Scale) >= abs(Scale) holds in the presence of // potentially wrapping math. auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) { diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4e6e666922671d..8955de6375dec4 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1586,10 +1586,10 @@ static Value *simplifyUnsignedRang