Mustakimur Khandaker via llvm-dev
2018-Apr-15 18:44 UTC
[llvm-dev] LLVM Alias Analysis (Load and store from same address is not showed up in same set)
Hi I have this simple c code for which I would like to use for alias analysis. #include <stdio.h> #include <stdlib.h> static int (*fp) (void); void ind_call (int (*compr)(void)){ fp = compr; fp(); } int hello(void){ return printf("hello world\n"); } int main(){ ind_call(hello); return 0; } So, I do the following: bin/opt -basicaa -cfl-anders-aa -print-alias-sets bin/test/test.bc I get the following result: Alias sets for function 'ind_call': Alias Set Tracker: 2 alias sets for 2 pointer values. AliasSet[0x91a5820, 1] must alias, Mod/Ref Pointers: (i32 ()** %compr.addr, 8) AliasSet[0x91a58c0, 2] may alias, Mod/Ref Pointers: (i32 ()** @fp, 8) 1 Unknown instructions: i32 %call Alias sets for function 'hello': Alias Set Tracker: 1 alias sets for 0 pointer values. AliasSet[0x91a5910, 1] may alias, Mod/Ref 1 Unknown instructions: i32 %call Alias sets for function 'main': Alias Set Tracker: 2 alias sets for 1 pointer values. AliasSet[0x91a5a50, 1] must alias, Mod Pointers: (i32* %retval, 4) AliasSet[0x91a5aa0, 1] may alias, Mod/Ref 1 Unknown instructions: void <badref> My question is from c code when we can notice that fp and compr target to same address (because of fp = compr), why they are not in the same alias set. As you can see, for function ind_call, the alias set that contain fp is along, while from my understanding there should be another alias compr. For better understanding, I also include the LLVM IR here (generated by LLVM-7.0): ; ModuleID = 'test.c' source_filename = "test.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @fp = internal global i32 ()* null, align 8 @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1 ; Function Attrs: noinline nounwind optnone uwtable define dso_local void @ind_call(i32 ()* %compr) #0 { entry: %compr.addr = alloca i32 ()*, align 8 store i32 ()* %compr, i32 ()** %compr.addr, align 8 %0 = load i32 ()*, i32 ()** %compr.addr, align 8 store i32 ()* %0, i32 ()** @fp, align 8 %1 = load i32 ()*, i32 ()** @fp, align 8 %call = call i32 %1() ret void } ; Function Attrs: noinline nounwind optnone uwtable define dso_local i32 @hello() #0 { entry: %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0)) ret i32 %call } declare dso_local i32 @printf(i8*, ...) #1 ; Function Attrs: noinline nounwind optnone uwtable define dso_local i32 @main() #0 { entry: %retval = alloca i32, align 4 store i32 0, i32* %retval, align 4 call void @ind_call(i32 ()* @hello) ret i32 0 } Best Regards Mustakimur Rahman Khandaker Graduate Student and Research Assistant Department of Computer Science Florida State University -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180415/f395ab0a/attachment.html>
Friedman, Eli via llvm-dev
2018-Apr-16 17:51 UTC
[llvm-dev] LLVM Alias Analysis (Load and store from same address is not showed up in same set)
On 4/15/2018 11:44 AM, Mustakimur Khandaker via llvm-dev wrote:> Hi > I have this simple c code for which I would like to use for alias > analysis. > > #include <stdio.h> > #include <stdlib.h> > > static int (*fp) (void); > void ind_call (int (*compr)(void)){ > fp = compr; > fp(); > } > int hello(void){ > return printf("hello world\n"); > } > int main(){ > ind_call(hello); > return 0; > } > > > So, I do the following: > > bin/opt -basicaa -cfl-anders-aa -print-alias-sets bin/test/test.bc > > > I get the following result: > > Alias sets for function 'ind_call': > Alias Set Tracker: 2 alias sets for 2 pointer values. > AliasSet[0x91a5820, 1] must alias, Mod/Ref Pointers: (i32 ()** > %compr.addr, 8) > AliasSet[0x91a58c0, 2] may alias, Mod/Ref Pointers: (i32 ()** > @fp, 8) > 1 Unknown instructions: i32 %call >LLVM's alias analysis is not very smart; it depends on other optimization passes to produce reasonable results. You should at least run mem2reg before trying to do any alias analysis queries. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180416/f243179c/attachment.html>
Mustakimur Khandaker via llvm-dev
2018-Apr-16 18:13 UTC
[llvm-dev] LLVM Alias Analysis (Load and store from same address is not showed up in same set)
Okay, I have tried the following: bin/opt -mem2reg -basicaa -cfl-anders-aa -print-alias-sets bin/test/test.bc But, the result is same as last time. Do you mean something like this to try? Can you suggest what else could be an important factor for this issue? Best Regards Mustakimur Rahman Khandaker Graduate Student and Teaching Assistant Department of Computer Science Florida State University ________________________________ From: Friedman, Eli <efriedma at codeaurora.org> Sent: Monday, April 16, 2018 1:51:14 PM To: Mustakimur Khandaker; llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] LLVM Alias Analysis (Load and store from same address is not showed up in same set) On 4/15/2018 11:44 AM, Mustakimur Khandaker via llvm-dev wrote: Hi I have this simple c code for which I would like to use for alias analysis. #include <stdio.h> #include <stdlib.h> static int (*fp) (void); void ind_call (int (*compr)(void)){ fp = compr; fp(); } int hello(void){ return printf("hello world\n"); } int main(){ ind_call(hello); return 0; } So, I do the following: bin/opt -basicaa -cfl-anders-aa -print-alias-sets bin/test/test.bc I get the following result: Alias sets for function 'ind_call': Alias Set Tracker: 2 alias sets for 2 pointer values. AliasSet[0x91a5820, 1] must alias, Mod/Ref Pointers: (i32 ()** %compr.addr, 8) AliasSet[0x91a58c0, 2] may alias, Mod/Ref Pointers: (i32 ()** @fp, 8) 1 Unknown instructions: i32 %call LLVM's alias analysis is not very smart; it depends on other optimization passes to produce reasonable results. You should at least run mem2reg before trying to do any alias analysis queries. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180416/3b149eef/attachment.html>
Possibly Parallel Threads
- LLVM Alias Analysis (Load and store from same address is not showed up in same set)
- LLVM Alias Analysis (Load and store from same address is not showed up in same set)
- [cfe-dev] Create a BlockAddress array from LLVM Pass
- Create the GlobalVariable which have extern in one header file
- Create a BlockAddress array from LLVM Pass