[PATCH] D79528: [ConstantFold] Optimize xor undef, undef to undef
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 17:04:25 PDT 2020
aqjune created this revision.
aqjune added reviewers: spatel, RKSimon, efriedma, lebedev.ri, lattner.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This patch makes ConstantFold optimize xor undef, undef to undef , which was mentioned at D79452 <https://reviews.llvm.org/D79452>.
Correctness of the transformation: http://volta.cs.utah.edu:8080/z/GAs5QJ
Checked that it did not miscompile testsuite & SPECCPU 2017 . The used testsuite commit was 44dad74558616adcdf54a289db4466c7ab7d2563
because more recent testsuite raised https://bugs.llvm.org/show_bug.cgi?id=45818 (with & without this change).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79528
Files:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Analysis/ConstantFolding/vscale.ll
llvm/test/Transforms/InstCombine/xor-undef.ll
Index: llvm/test/Transforms/InstCombine/xor-undef.ll
===================================================================
--- llvm/test/Transforms/InstCombine/xor-undef.ll
+++ llvm/test/Transforms/InstCombine/xor-undef.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -instcombine -S | grep zeroinitializer
+; RUN: opt < %s -instcombine -S | grep "ret <2 x i64> undef"
define <2 x i64> @f() {
%tmp = xor <2 x i64> undef, undef
Index: llvm/test/Analysis/ConstantFolding/vscale.ll
===================================================================
--- llvm/test/Analysis/ConstantFolding/vscale.ll
+++ llvm/test/Analysis/ConstantFolding/vscale.ll
@@ -159,7 +159,7 @@
define <vscale x 4 x i32> @xor() {
; CHECK-LABEL: @xor(
-; CHECK-NEXT: ret <vscale x 4 x i32> zeroinitializer
+; CHECK-NEXT: ret <vscale x 4 x i32> undef
;
%r = xor <vscale x 4 x i32> undef, undef
ret <vscale x 4 x i32> %r
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -1053,9 +1053,8 @@
switch (static_cast<Instruction::BinaryOps>(Opcode)) {
case Instruction::Xor:
if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
- // Handle undef ^ undef -> 0 special case. This is a common
- // idiom (misuse).
- return Constant::getNullValue(C1->getType());
+ // undef ^ undef -> undef
+ return C1;
LLVM_FALLTHROUGH;
case Instruction::Add:
case Instruction::Sub:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79528.262502.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200507/87095b3e/attachment-0001.bin>
More information about the llvm-commits
mailing list