[PATCH] D51922: [NewGVN] Apply SimplifySelectInst if any of the options is undef.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 11 03:37:02 PDT 2018
fhahn created this revision.
fhahn added reviewers: efriedma, nlopes, davide.
Herald added a subscriber: Prazek.
The Simplify* functions expect undefs to be replaced as we go along, to
avoid the same undef use being used with different values.
See PR33165 for an extensive discussion of the issue.
https://reviews.llvm.org/D51922
Files:
lib/Transforms/Scalar/NewGVN.cpp
test/Transforms/NewGVN/pr33165.ll
Index: test/Transforms/NewGVN/pr33165.ll
===================================================================
--- /dev/null
+++ test/Transforms/NewGVN/pr33165.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -newgvn -S < %s | FileCheck %s
+
+define i2 @t1(i2, i1) {
+; CHECK-LABEL: @t1(
+; CHECK-NEXT: [[A:%.*]] = xor i2 [[TMP0:%.*]], -1
+; CHECK-NEXT: ret i2 [[A]]
+;
+ %a = xor i2 %0, -1
+ %b = select i1 %1, i2 %a, i2 undef
+ %c = and i2 %a, %b
+ ret i2 %c
+}
+
+define i2 @t2(i2, i1) {
+; CHECK-LABEL: @t2(
+; CHECK-NEXT: [[A:%.*]] = xor i2 [[TMP0:%.*]], -1
+; CHECK-NEXT: ret i2 [[A]]
+;
+ %a = xor i2 %0, -1
+ %b = select i1 %1, i2 undef, i2 %a
+ %c = and i2 %a, %b
+ ret i2 %c
+}
Index: lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- lib/Transforms/Scalar/NewGVN.cpp
+++ lib/Transforms/Scalar/NewGVN.cpp
@@ -1151,7 +1151,9 @@
return SimplifiedE;
} else if (isa<SelectInst>(I)) {
if (isa<Constant>(E->getOperand(0)) ||
- E->getOperand(1) == E->getOperand(2)) {
+ E->getOperand(1) == E->getOperand(2) ||
+ isa<UndefValue>(E->getOperand(1)) ||
+ isa<UndefValue>(E->getOperand(2))) {
assert(E->getOperand(1)->getType() == I->getOperand(1)->getType() &&
E->getOperand(2)->getType() == I->getOperand(2)->getType());
Value *V = SimplifySelectInst(E->getOperand(0), E->getOperand(1),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51922.164839.patch
Type: text/x-patch
Size: 1489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/41302528/attachment.bin>
More information about the llvm-commits
mailing list