From 5bce67a95feb136389ca630cc5dd6a81e97ff1eb Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 2 Jul 2013 09:58:53 +0000 Subject: [PATCH] DAGCombiner: fix use-counting issue when forming zextload DAGCombiner was counting all uses of a load node when considering whether it's worth combining into a zextload. Really, it wants to ignore the chain and just count real uses. rdar://problem/13896307 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185419 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 2 +- test/CodeGen/X86/simple-zext.ll | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/X86/simple-zext.ll diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 00469b0f32a..1688fc495ad 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2755,7 +2755,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) { ? cast(N0.getOperand(0)) : cast(N0); if (LN0->getExtensionType() != ISD::SEXTLOAD && - LN0->isUnindexed() && N0.hasOneUse() && LN0->hasOneUse()) { + LN0->isUnindexed() && N0.hasOneUse() && SDValue(LN0, 0).hasOneUse()) { uint32_t ActiveBits = N1C->getAPIntValue().getActiveBits(); if (ActiveBits > 0 && APIntOps::isMask(ActiveBits, N1C->getAPIntValue())){ EVT ExtVT = EVT::getIntegerVT(*DAG.getContext(), ActiveBits); diff --git a/test/CodeGen/X86/simple-zext.ll b/test/CodeGen/X86/simple-zext.ll new file mode 100644 index 00000000000..ccd8292bcdb --- /dev/null +++ b/test/CodeGen/X86/simple-zext.ll @@ -0,0 +1,16 @@ +; RUN: llc -mtriple=x86_64-apple-darwin < %s| FileCheck %s + +; A bug in DAGCombiner prevented it forming a zextload in this simple case +; because it counted both the chain user and the real user against the +; profitability total. + +define void @load_zext(i32* nocapture %p){ +entry: + %0 = load i32* %p, align 4 + %and = and i32 %0, 255 + tail call void @use(i32 %and) + ret void +; CHECK: movzbl ({{%r[a-z]+}}), {{%e[a-z]+}} +} + +declare void @use(i32) -- 2.34.1