[llvm] [clang] split load to bytes to deduce load value (PR #72364)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 02:31:38 PST 2023


================
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4
----------------
nikic wrote:

```suggestion
// define i32 @f(ptr %P)
// 1:  %b2 = getelementptr inbounds i8, ptr %P, i64 1
// 2:  store i8 0, ptr %b2, align 1
// 3:  store i8 0, ptr %P, align 1
// 5:  %L = load i16, ptr %P, align 4
```

https://github.com/llvm/llvm-project/pull/72364


More information about the llvm-commits mailing list