[llvm-dev] DSE: Remove useless stores between malloc & memset

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Thu May 17 12:00:23 PDT 2018


On 5/17/2018 8:58 AM, Dávid Bolvanský via llvm-dev wrote:
> Hello,
>
> I would like to find a way to do this removal properly. I found DSE 
> and "eliminateNoopStore" can be useful for this thing.
>
> What I mean?
> int *test = malloc(15 * sizeof(int));
> test[10] = 12; < ----- remove this store
> memset(test,0,sizeof(int) * 15);

This is classic dead store elimination, and it's already handled by DSE. 
At least, we optimize the following testcase:

#include <stdlib.h>
#include <string.h>
void bar(int*);
void f() {
   int *test = malloc(15 * sizeof(int));
   test[10] = 12;
   memset(test,0,sizeof(int) * 15);
   bar(test);
}

You should be able to look at the existing code to understand how it's 
handled (using MemoryDependenceAnalysis).

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list