You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh, I see your link goes to a site where "gc (tip)" is selected. But it's faster for us if you put all the relevant information in the bug. And conventionally we share play.golang.org code snippets. But in this case you can just inline the code:
Sorry, @bradfitz. I just assumed that you were familiar with Godbolt and, as you found out, the version is displayed there. But I'll take note for future reference.
True, that makes it trickier. We'd either have to recognize the results of the div->mul lowering (generic.rules:1161), or push the div->mul lowering later. Both seem challenging.
Maybe we should split div reduction out of generic into its own pass that runs late. It sounds something that later passes aren't dependent upon, and it tends to make code harder to analyze for everybody.
I see opt and late opt use the same function opt. It seems to be hard without break current function signature, or using a global variable to toggle apply div reduction for it.
Also, for clarification, is IsInBounds will be applied in prove pass?
I see opt and late opt use the same function opt. It seems to be hard without break current function signature, or using a global variable to toggle apply div reduction for it.
They use the same rule file, yes. But you can condition the rules on the pass. I thought we had an example of this already, but apparently not. I think just adding && v.Block.Func.pass.name == "..." would do it.
Also, for clarification, is IsInBounds will be applied in prove pass?
Yes, most of the bounds check removal happens in the prove pass.
I can dust off and complete that particular CL, though, if that would be helpful
@josharian I think your CL would leave the mod in place, then could the IsInBounds be removed with (no need for prove)?
(IsInBounds (Mod32u _ x) y) && x <= y -> (ConstBool [1])
(IsInBounds (Mod64u _ x) y) && x <= y -> (ConstBool [1])
Also, won't some of the other Mod rules still trigger whenever the constant is a power of two? (Mod32u <t> n (Const32 [c])) && isPowerOfTwo(c&0xffffffff) -> (And32 n (Const32 <t> [(c&0xffffffff)-1]))
If those are also not needed by passes between opt and lateopt, they could also be skipped and then removed by the above rule? I'll try, but would love a sanity check first.
(At that point, you're well on your way to taking over my efforts to delete func bounded from walk.go, which I would be delighted by. See also the other CLs linked in the "Relation chain" from any of those CLs.)
Also, won't some of the other Mod rules still trigger whenever the constant is a power of two?
Yes, but boundedness and And are easy to reason about in a way that magic division is not; we should just add additional rules to remove IsInBounds based on bit masks. I believe some of the CLs linked above do some of that.
IMO, for simple things adding them to the rewrite pass is preferable, since it provides the opportunity for other rewrite rules to keep working on the simplified form. And rules are pretty easy to read and maintain.
@randall77 This appears to have been solved on the latest dev branch (note that the code needs to be rewritten to avoid being optimized out completely).
Activity
bradfitz commentedon Jan 22, 2019
Please use the issue template.
You don't specify what version of Go, for one, or which compiler.
bradfitz commentedon Jan 22, 2019
Oh, I see your link goes to a site where "gc (tip)" is selected. But it's faster for us if you put all the relevant information in the bug. And conventionally we share play.golang.org code snippets. But in this case you can just inline the code:
/cc @randall77 @aclements
mariecurried commentedon Jan 22, 2019
Sorry, @bradfitz. I just assumed that you were familiar with Godbolt and, as you found out, the version is displayed there. But I'll take note for future reference.
randall77 commentedon Jan 22, 2019
I think this would just involve adding a new case for unsigned remainder to the prove pass.
josharian commentedon Jan 22, 2019
cc @rasky
cuonglm commentedon Apr 4, 2019
@randall77 Where should I look at in the source to fix this?
I see the current behavior convert the
Mod64uto aSub64, so prove failed.If I assigned
i = <any non negative number>before if, prove success, as it seesConst64.randall77 commentedon Apr 4, 2019
True, that makes it trickier. We'd either have to recognize the results of the div->mul lowering (generic.rules:1161), or push the div->mul lowering later. Both seem challenging.
rasky commentedon Apr 4, 2019
Maybe we should split div reduction out of generic into its own pass that runs late. It sounds something that later passes aren't dependent upon, and it tends to make code harder to analyze for everybody.
josharian commentedon Apr 4, 2019
cc also @zdjones
8 remaining items
cuonglm commentedon Apr 22, 2019
I see
optandlate optuse the same functionopt. It seems to be hard without break current function signature, or using a global variable to toggle apply div reduction for it.Also, for clarification, is
IsInBoundswill be applied inprovepass?randall77 commentedon Apr 22, 2019
They use the same rule file, yes. But you can condition the rules on the pass. I thought we had an example of this already, but apparently not. I think just adding
&& v.Block.Func.pass.name == "..."would do it.Yes, most of the bounds check removal happens in the prove pass.
josharian commentedon Apr 22, 2019
This is https://go-review.googlesource.com/c/go/+/129379, which is on hold because it was part of an effort to move some BCE from walk.go to SSA, and I never finished the project. I can dust off and complete that particular CL, though, if that would be helpful. Also, @bmkessler's modulus changes may do something similar. (https://go-review.googlesource.com/c/go/+/168037?)
zdjones commentedon Apr 22, 2019
@josharian I think your CL would leave the mod in place, then could the IsInBounds be removed with (no need for prove)?
Also, won't some of the other Mod rules still trigger whenever the constant is a power of two?
(Mod32u <t> n (Const32 [c])) && isPowerOfTwo(c&0xffffffff) -> (And32 n (Const32 <t> [(c&0xffffffff)-1]))If those are also not needed by passes between opt and lateopt, they could also be skipped and then removed by the above rule? I'll try, but would love a sanity check first.
josharian commentedon Apr 22, 2019
Yes, some of the
IsInBoundscould be removed during the rewrite rules. I started on this in (e.g.) https://go-review.googlesource.com/c/go/+/129383 and https://go-review.googlesource.com/c/go/+/129380. You might also want something like https://go-review.googlesource.com/c/go/+/129384 so that you can easily add tests.(At that point, you're well on your way to taking over my efforts to delete
func boundedfromwalk.go, which I would be delighted by. See also the other CLs linked in the "Relation chain" from any of those CLs.)Yes, but boundedness and
Andare easy to reason about in a way that magic division is not; we should just add additional rules to removeIsInBoundsbased on bit masks. I believe some of the CLs linked above do some of that.zdjones commentedon Apr 22, 2019
Yeah, when I first saw this issue, I started trying to reason my way back through the reduced mod...and abandoned that idea pretty quickly.
Is there any preference in using a rewrite rule vs the prove pass (i.e. due to differences in performance, complexity/maintenance, etc.)?
josharian commentedon Apr 22, 2019
IMO, for simple things adding them to the rewrite pass is preferable, since it provides the opportunity for other rewrite rules to keep working on the simplified form. And rules are pretty easy to read and maintain.
cuonglm commentedon Apr 23, 2019
@zdjones
I tried but the bounds check is still there. I think we have to add some thing to fact table, like @randall77 said in comment above.
fice-t commentedon Nov 19, 2025
@randall77 This appears to have been solved on the latest dev branch (note that the code needs to be rewritten to avoid being optimized out completely).
randall77 commentedon Nov 19, 2025
@fice-t thanks. Probably CL 714160 or one of the CLs around it.
Closing.