[PATCH] D146034: [TTI] Treat AND/OR with widenable conditions as free of cost
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 06:55:34 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd12af65d4626: [TTI] Treat AND/OR with widenable conditions as free of cost (authored by mkazantsev).
Changed prior to commit:
https://reviews.llvm.org/D146034?vs=505035&id=505080#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146034/new/
https://reviews.llvm.org/D146034
Files:
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/test/Transforms/LoopUnroll/guard-cost-for-unrolling.ll
Index: llvm/test/Transforms/LoopUnroll/guard-cost-for-unrolling.ll
===================================================================
--- llvm/test/Transforms/LoopUnroll/guard-cost-for-unrolling.ll
+++ llvm/test/Transforms/LoopUnroll/guard-cost-for-unrolling.ll
@@ -2,7 +2,7 @@
; REQUIRES: asserts
-; FIXME: This test is needed to make sure that the guard cost remains the same,
+; This test is needed to make sure that the guard cost remains the same,
; independently on guard representation form (either intrinsic call or branch with
; widenable condition).
@@ -30,7 +30,7 @@
define void @test_guard_as_branch(ptr %arr, i64 %n, i64 %bound) {
; CHECK-LABEL: Loop Unroll: F[test_guard_as_branch] Loop %loop
-; CHECK-NEXT: Loop Size = 9
+; CHECK-NEXT: Loop Size = 8
; CHECK-NEXT: runtime unrolling with count: 2
entry:
br label %loop
Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -499,6 +499,14 @@
TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info,
ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) const {
+ // Widenable conditions will eventually lower into constants, so some
+ // operations with them will be trivially optimized away.
+ auto IsWidenableCondition = [](const Value *V) {
+ if (auto *II = dyn_cast<IntrinsicInst>(V))
+ if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
+ return true;
+ return false;
+ };
// FIXME: A number of transformation tests seem to require these values
// which seems a little odd for how arbitary there are.
switch (Opcode) {
@@ -512,6 +520,11 @@
case Instruction::URem:
// FIXME: Unlikely to be true for CodeSize.
return TTI::TCC_Expensive;
+ case Instruction::And:
+ case Instruction::Or:
+ if (any_of(Args, IsWidenableCondition))
+ return TTI::TCC_Free;
+ break;
}
// Assume a 3cy latency for fp arithmetic ops.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146034.505080.patch
Type: text/x-patch
Size: 2163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230314/4bc10aff/attachment.bin>
More information about the llvm-commits
mailing list