[PATCH] D109867: [ValueTracking] Enhance DemandedElts support to PhiNode
zhengping.hu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 16 20:48:05 PDT 2021
xjtuhu updated this revision to Diff 373137.
xjtuhu added a comment.
update the test after using update_test_checks.py
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109867/new/
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,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; 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) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: call void @foo4x32(<4 x i32> <i32 0, i32 1, i32 2, i32 3>)
+; CHECK-NEXT: br i1 true, label [[TAKEN:%.*]], label [[NOTTAKEN:%.*]]
+; CHECK: taken:
+; CHECK-NEXT: ret i1 true
+; CHECK: nottaken:
+; CHECK-NEXT: br i1 undef, label [[END:%.*]], label [[BODY]]
+; CHECK: end:
+; CHECK-NEXT: ret i1 false
+;
+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
+}
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.373137.patch
Type: text/x-patch
Size: 2478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210917/2339927c/attachment.bin>
More information about the llvm-commits
mailing list