This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt]: See if it's possible to shrink Stores with Undef during global variable initialization to eliminate constructor functions
Needs ReviewPublic

Authored by aditya_nandakumar on Sep 27 2016, 11:44 AM.

Details

Reviewers
majnemer
pcc
Summary

Suppose we have
@_ZL9aPosition = internal addrspace(2) global [1 x <3 x float>] zeroinitializer, align 16
and global_var_init function does
store <4 x float> <float 4.000000e+00, float 4.000000e+00, float 4.000000e+00, float undef>, <4 x float> addrspace(2)* bitcast ([1 x <3 x float>] addrspace(2)* @_ZL9aPosition to <4 x float> addrspace(2)*), !tbaa !7

We can optimize this init function away by checking if the store has trailing undefs and if the types become compatible by shrinking the stores.

Looking forward to your feedback.

Diff Detail

Event Timeline

aditya_nandakumar retitled this revision from to [GlobalOpt]: See if it's possible to shrink Stores with Undef during global variable initialization to eliminate constructor functions.
aditya_nandakumar updated this object.
aditya_nandakumar added reviewers: pcc, majnemer.
aditya_nandakumar set the repository for this revision to rL LLVM.
aditya_nandakumar added a subscriber: llvm-commits.
majnemer edited edge metadata.Oct 4 2016, 6:06 PM

Please use clang-format on your diff.

lib/Transforms/Utils/Evaluator.cpp
253–294

auto *

263–264

auto *

269

Please end comments with a period.

272–277

This loop looks a little confusing, why not loop from ElemTy->getNumElements() to ValSize?

274

!isa<UndefValue>(V)

test/Transforms/GlobalOpt/ShrinkUndefStore.ll
2

It is more common to see:

; RUN: opt -globalopt -S < %s | FileCheck %s
3

Please have more thorough CHECKs.

19–27

Please remove these Mach-O section attributes.

aditya_nandakumar edited edge metadata.
aditya_nandakumar removed rL LLVM as the repository for this revision.

Thanks David.

Updated based on your comments + Clang Formatted.

David - did you get a chance to look at the updated diff?
Thanks