[PATCH] D109867: [ValueTracking] Enhance DemandedElts support to PhiNode
zhengping.hu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 15 21:02:24 PDT 2021
xjtuhu created this revision.
xjtuhu added reviewers: spatel, lebedev.ri, reames.
Herald added a subscriber: hiraditya.
xjtuhu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109867
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstCombine/phi-known-bits-demandedelts.ll
Index: llvm/test/Transforms/InstCombine/phi-known-bits-demandedelts.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/phi-known-bits-demandedelts.ll
@@ -0,0 +1,30 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+; CHECK: br i1 true, label %taken, label %nottaken
+declare void @foo4x32(<4 x i32>)
+
+define i1 @test(i32 %count) {
+entry:
+ br label %body
+
+body:
+ %index = phi i32 [ 0, %entry ], [ %index.next, %nottaken ]
+ %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %entry ], [ %vec.ind.next, %nottaken ]
+ call void @foo4x32(<4 x i32> %vec.ind)
+ %a = extractelement <4 x i32> %vec.ind, i32 0
+ %b = and i32 %a, 3
+ %cmp1 = icmp eq i32 %b, 0 ;; should be always true
+ br i1 %cmp1, label %taken, label %nottaken
+
+taken:
+ ret i1 true
+
+nottaken:
+ %index.next = add i32 %index, 4
+ %vec.ind.next = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
+ %cmp2 = icmp eq i32 %index.next, %count
+ br i1 %cmp2, label %end, label %body
+
+end:
+ ret i1 false
+}
\ No newline at end of file
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -1457,12 +1457,12 @@
// Ok, we have a PHI of the form L op= R. Check for low
// zero bits.
RecQ.CxtI = RInst;
- computeKnownBits(R, Known2, Depth + 1, RecQ);
+ computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ);
// We need to take the minimum number of known bits
KnownBits Known3(BitWidth);
RecQ.CxtI = LInst;
- computeKnownBits(L, Known3, Depth + 1, RecQ);
+ computeKnownBits(L, DemandedElts, Known3, Depth + 1, RecQ);
Known.Zero.setLowBits(std::min(Known2.countMinTrailingZeros(),
Known3.countMinTrailingZeros()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109867.372861.patch
Type: text/x-patch
Size: 1973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210916/6b2d8091/attachment.bin>
More information about the llvm-commits
mailing list