[llvm] [InstCombine] Do not use operand info in `replaceInInstruction` (PR #99492)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 06:53:30 PDT 2024
================
@@ -4713,3 +4713,24 @@ define i8 @select_knownbits_simplify_missing_noundef(i8 %x) {
%res = select i1 %cmp, i8 %and, i8 0
ret i8 %res
}
+
+ at arr = global [2 x i32] zeroinitializer, align 4
+ at cst = constant ptr getelementptr (i8, ptr @arr, i64 4)
+
+define i32 @pr99436() {
+; CHECK-LABEL: @pr99436(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr (i8, ptr @arr, i64 4), null
+; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr getelementptr (i8, ptr @arr, i64 4), align 4
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[CMP]], i32 [[VAL]], i32 0
+; CHECK-NEXT: ret i32 [[RET]]
+;
+entry:
+ %alloc = alloca ptr, align 8
+ call void @llvm.memcpy.p0.p0.i64(ptr align 8 %alloc, ptr align 8 @cst, i64 8, i1 false)
----------------
nikic wrote:
How about this?
```llvm
@g = external global i8
define i32 @test(ptr align 4 dereferenceable(4) %ptr) {
%cmp = icmp eq ptr %ptr, @g
%val = load i32, ptr %ptr, align 4
%ret = select i1 %cmp, i32 %val, i32 0
ret i32 %ret
}
```
It's not quite as nice as the replacement with null, but `@g` is still potentially non-derefable.
https://github.com/llvm/llvm-project/pull/99492
More information about the llvm-commits
mailing list